mirror of
https://github.com/strawberrymusicplayer/strawberry
synced 2025-01-31 09:44:50 +01:00
Fix resume playback on startup
This commit is contained in:
parent
8fe0229a2c
commit
ca140388d9
@ -71,6 +71,7 @@ Version 0.5.3:
|
||||
* Removed API Seeds lyrics provider (require payment)
|
||||
* Added group by format
|
||||
* Fixed gstreamer leaks
|
||||
* Fixed resume playback on startup not working for other than the first playlist
|
||||
|
||||
Version 0.5.2:
|
||||
|
||||
|
@ -794,7 +794,9 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co
|
||||
|
||||
CommandlineOptionsReceived(options);
|
||||
|
||||
if (!options.contains_play_options()) LoadPlaybackStatus();
|
||||
if (!options.contains_play_options()) {
|
||||
LoadPlaybackStatus();
|
||||
}
|
||||
|
||||
RefreshStyleSheet();
|
||||
|
||||
@ -1027,49 +1029,45 @@ void MainWindow::SaveGeometry() {
|
||||
|
||||
void MainWindow::SavePlaybackStatus() {
|
||||
|
||||
QSettings settings;
|
||||
QSettings s;
|
||||
|
||||
settings.beginGroup("Player");
|
||||
settings.setValue("playback_state", app_->player()->GetState());
|
||||
s.beginGroup(Player::kSettingsGroup);
|
||||
s.setValue("playback_state", app_->player()->GetState());
|
||||
if (app_->player()->GetState() == Engine::Playing || app_->player()->GetState() == Engine::Paused) {
|
||||
settings.setValue("playback_position", app_->player()->engine()->position_nanosec() / kNsecPerSec);
|
||||
s.setValue("playback_position", app_->player()->engine()->position_nanosec() / kNsecPerSec);
|
||||
}
|
||||
else {
|
||||
settings.setValue("playback_position", 0);
|
||||
s.setValue("playback_position", 0);
|
||||
}
|
||||
|
||||
settings.endGroup();
|
||||
s.endGroup();
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::LoadPlaybackStatus() {
|
||||
|
||||
QSettings settings;
|
||||
QSettings s;
|
||||
|
||||
settings.beginGroup(BehaviourSettingsPage::kSettingsGroup);
|
||||
bool resume_playback = settings.value("resumeplayback", false).toBool();
|
||||
settings.endGroup();
|
||||
s.beginGroup(BehaviourSettingsPage::kSettingsGroup);
|
||||
bool resume_playback = s.value("resumeplayback", false).toBool();
|
||||
s.endGroup();
|
||||
|
||||
if (!resume_playback) return;
|
||||
s.beginGroup(Player::kSettingsGroup);
|
||||
saved_playback_state_ = static_cast<Engine::State> (s.value("playback_state", Engine::Empty).toInt());
|
||||
saved_playback_position_ = s.value("playback_position", 0).toDouble();
|
||||
s.endGroup();
|
||||
|
||||
settings.beginGroup("Player");
|
||||
saved_playback_state_ = static_cast<Engine::State> (settings.value("playback_state", Engine::Empty).toInt());
|
||||
saved_playback_position_ = settings.value("playback_position", 0).toDouble();
|
||||
settings.endGroup();
|
||||
|
||||
if (saved_playback_state_ == Engine::Empty || saved_playback_state_ == Engine::Idle) {
|
||||
return;
|
||||
if (resume_playback && saved_playback_state_ != Engine::Empty && saved_playback_state_ != Engine::Idle) {
|
||||
connect(app_->playlist_manager(), SIGNAL(AllPlaylistsLoaded()), SLOT(ResumePlayback()));
|
||||
}
|
||||
|
||||
connect(app_->playlist_manager()->active(), SIGNAL(RestoreFinished()), SLOT(ResumePlayback()));
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::ResumePlayback() {
|
||||
|
||||
qLog(Debug) << "Resuming playback";
|
||||
|
||||
disconnect(app_->playlist_manager()->active(), SIGNAL(RestoreFinished()), this, SLOT(ResumePlayback()));
|
||||
disconnect(app_->playlist_manager(), SIGNAL(AllPlaylistsLoaded()), this, SLOT(ResumePlayback()));
|
||||
|
||||
if (saved_playback_state_ == Engine::Paused) {
|
||||
NewClosure(app_->player(), SIGNAL(Playing()), app_->player(), SLOT(PlayPause()));
|
||||
|
@ -420,11 +420,9 @@ void Player::PlayPause() {
|
||||
case Engine::Idle: {
|
||||
app_->playlist_manager()->SetActivePlaylist(app_->playlist_manager()->current_id());
|
||||
if (app_->playlist_manager()->active()->rowCount() == 0) break;
|
||||
|
||||
int i = app_->playlist_manager()->active()->current_row();
|
||||
if (i == -1) i = app_->playlist_manager()->active()->last_played_row();
|
||||
if (i == -1) i = 0;
|
||||
|
||||
PlayAt(i, Engine::First, true);
|
||||
break;
|
||||
}
|
||||
|
@ -1339,6 +1339,8 @@ void Playlist::ItemsLoaded(QFuture<PlaylistItemList> future) {
|
||||
QtConcurrent::run(this, &Playlist::InvalidateDeletedSongs);
|
||||
}
|
||||
|
||||
emit PlaylistLoaded();
|
||||
|
||||
}
|
||||
|
||||
static bool DescendingIntLessThan(int a, int b) { return a > b; }
|
||||
|
@ -300,6 +300,7 @@ class Playlist : public QAbstractListModel {
|
||||
|
||||
signals:
|
||||
void RestoreFinished();
|
||||
void PlaylistLoaded();
|
||||
void CurrentSongChanged(const Song &metadata);
|
||||
void EditingFinished(const QModelIndex &index);
|
||||
void PlayRequested(const QModelIndex &index);
|
||||
|
@ -68,7 +68,8 @@ PlaylistManager::PlaylistManager(Application *app, QObject *parent)
|
||||
parser_(nullptr),
|
||||
playlist_container_(nullptr),
|
||||
current_(-1),
|
||||
active_(-1)
|
||||
active_(-1),
|
||||
playlists_loading_(0)
|
||||
{
|
||||
connect(app_->player(), SIGNAL(Paused()), SLOT(SetActivePaused()));
|
||||
connect(app_->player(), SIGNAL(Playing()), SLOT(SetActivePlaying()));
|
||||
@ -93,7 +94,9 @@ void PlaylistManager::Init(CollectionBackend *collection_backend, PlaylistBacken
|
||||
connect(collection_backend_, SIGNAL(SongsStatisticsChanged(SongList)), SLOT(SongsDiscovered(SongList)));
|
||||
|
||||
for (const PlaylistBackend::Playlist &p : playlist_backend->GetAllOpenPlaylists()) {
|
||||
AddPlaylist(p.id, p.name, p.special_type, p.ui_path, p.favorite);
|
||||
playlists_loading_++;
|
||||
Playlist *ret = AddPlaylist(p.id, p.name, p.special_type, p.ui_path, p.favorite);
|
||||
connect(ret, SIGNAL(PlaylistLoaded()), SLOT(PlaylistLoaded()));
|
||||
}
|
||||
|
||||
// If no playlist exists then make a new one
|
||||
@ -103,6 +106,16 @@ void PlaylistManager::Init(CollectionBackend *collection_backend, PlaylistBacken
|
||||
|
||||
}
|
||||
|
||||
void PlaylistManager::PlaylistLoaded() {
|
||||
|
||||
Playlist *playlist = qobject_cast<Playlist*>(sender());
|
||||
if (!playlist) return;
|
||||
disconnect(playlist, SIGNAL(PlaylistLoaded()), this, SLOT(PlaylistLoaded()));
|
||||
playlists_loading_--;
|
||||
if (playlists_loading_ == 0) emit AllPlaylistsLoaded();
|
||||
|
||||
}
|
||||
|
||||
QList<Playlist*> PlaylistManager::GetAllPlaylists() const {
|
||||
|
||||
QList<Playlist*> result;
|
||||
@ -359,8 +372,7 @@ void PlaylistManager::SetActivePlaylist(int id) {
|
||||
|
||||
Q_ASSERT(playlists_.contains(id));
|
||||
|
||||
// Kinda a hack: unset the current item from the old active playlist before
|
||||
// setting the new one
|
||||
// Kinda a hack: unset the current item from the old active playlist before setting the new one
|
||||
if (active_ != -1 && active_ != id) active()->set_current_row(-1);
|
||||
|
||||
active_ = id;
|
||||
|
@ -104,6 +104,7 @@ public slots:
|
||||
|
||||
signals:
|
||||
void PlaylistManagerInitialized();
|
||||
void AllPlaylistsLoaded();
|
||||
|
||||
void PlaylistAdded(int id, const QString &name, bool favorite);
|
||||
void PlaylistDeleted(int id);
|
||||
@ -213,6 +214,7 @@ class PlaylistManager : public PlaylistManagerInterface {
|
||||
void UpdateSummaryText();
|
||||
void SongsDiscovered(const SongList& songs);
|
||||
void ItemsLoadedForSavePlaylist(QFuture<SongList> future, const QString& filename, Playlist::Path path_type);
|
||||
void PlaylistLoaded();
|
||||
|
||||
private:
|
||||
Playlist *AddPlaylist(int id, const QString& name, const QString &special_type, const QString& ui_path, bool favorite);
|
||||
@ -237,6 +239,7 @@ class PlaylistManager : public PlaylistManagerInterface {
|
||||
|
||||
int current_;
|
||||
int active_;
|
||||
int playlists_loading_;
|
||||
};
|
||||
|
||||
#endif // PLAYLISTMANAGER_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user