diff --git a/src/ui/behavioursettingspage.cpp b/src/ui/behavioursettingspage.cpp
index ba3cd97e8..6abfddb9d 100644
--- a/src/ui/behavioursettingspage.cpp
+++ b/src/ui/behavioursettingspage.cpp
@@ -99,6 +99,7 @@ void BehaviourSettingsPage::Load() {
case MainWindow::Startup_AlwaysShow: ui_->b_always_show_->setChecked(true); break;
case MainWindow::Startup_Remember: ui_->b_remember_->setChecked(true); break;
}
+ ui_->resume_after_start_->setChecked(s.value("resume_playback_after_start", false).toBool());
s.endGroup();
s.beginGroup("General");
@@ -136,6 +137,7 @@ void BehaviourSettingsPage::Save() {
s.setValue("doubleclick_addmode", doubleclick_addmode);
s.setValue("doubleclick_playmode", doubleclick_playmode);
s.setValue("menu_playmode", menu_playmode);
+ s.setValue("resume_playback_after_start", ui_->resume_after_start_->isChecked());
s.endGroup();
s.beginGroup("General");
diff --git a/src/ui/behavioursettingspage.ui b/src/ui/behavioursettingspage.ui
index 8ad56eb1c..d9167a389 100644
--- a/src/ui/behavioursettingspage.ui
+++ b/src/ui/behavioursettingspage.ui
@@ -102,6 +102,16 @@
+ -
+
+
+ Resume playback on start
+
+
+ false
+
+
+
-
diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp
index 82d4e58c7..d960c6dd1 100644
--- a/src/ui/mainwindow.cpp
+++ b/src/ui/mainwindow.cpp
@@ -192,6 +192,8 @@ MainWindow::MainWindow(Application* app,
library_sort_model_(new QSortFilterProxyModel(this)),
track_position_timer_(new QTimer(this)),
was_maximized_(false),
+ saved_playback_position_(0),
+ saved_playback_state_(Engine::Empty),
doubleclick_addmode_(AddBehaviour_Append),
doubleclick_playmode_(PlayBehaviour_IfStopped),
menu_playmode_(PlayBehaviour_IfStopped)
@@ -754,6 +756,8 @@ MainWindow::MainWindow(Application* app,
CheckFullRescanRevisions();
+ LoadPlaybackStatus();
+
qLog(Debug) << "Started";
}
@@ -963,6 +967,45 @@ void MainWindow::SaveGeometry() {
settings_.setValue("tab_mode", ui_->tabs->mode());
}
+void MainWindow::SavePlaybackStatus() {
+ QSettings settings;
+ settings.beginGroup(MainWindow::kSettingsGroup);
+ settings.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);
+ } else {
+ settings.setValue("playback_position", 0);
+ }
+}
+
+void MainWindow::LoadPlaybackStatus() {
+ QSettings settings;
+ settings.beginGroup(MainWindow::kSettingsGroup);
+ bool resume_playback = settings.value("resume_playback_after_start", false).toBool();
+ saved_playback_state_ = static_cast
+ (settings.value("playback_state", Engine::Empty).toInt());
+ saved_playback_position_ = settings.value("playback_position", 0).toDouble();
+ if (!resume_playback ||
+ saved_playback_state_ == Engine::Empty ||
+ saved_playback_state_ == Engine::Idle) {
+ return;
+ }
+
+ QTimer::singleShot(100, this, SLOT(ResumePlayback()));
+}
+
+void MainWindow::ResumePlayback() {
+ qLog(Debug) << "Resuming playback";
+ app_->player()->Play();
+
+ app_->player()->SeekTo(saved_playback_position_);
+
+ if (saved_playback_state_ == Engine::Paused) {
+ app_->player()->Pause();
+ }
+}
+
void MainWindow::PlayIndex(const QModelIndex& index) {
if (!index.isValid())
return;
@@ -2098,6 +2141,7 @@ bool MainWindow::winEvent(MSG* msg, long*) {
#endif // Q_OS_WIN32
void MainWindow::Exit() {
+ SavePlaybackStatus();
if(app_->player()->engine()->is_fadeout_enabled()) {
// To shut down the application when fadeout will be finished
connect(app_->player()->engine(), SIGNAL(FadeoutFinishedSignal()), qApp, SLOT(quit()));
diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h
index 437993a2e..4afcded5f 100644
--- a/src/ui/mainwindow.h
+++ b/src/ui/mainwindow.h
@@ -238,6 +238,9 @@ class MainWindow : public QMainWindow, public PlatformInterface {
void ShowSongInfoConfig();
void SaveGeometry();
+ void SavePlaybackStatus();
+ void LoadPlaybackStatus();
+ void ResumePlayback();
void AddSongInfoGenerator(smart_playlists::GeneratorPtr gen);
@@ -335,6 +338,8 @@ class MainWindow : public QMainWindow, public PlatformInterface {
QSettings settings_;
bool was_maximized_;
+ int saved_playback_position_;
+ Engine::State saved_playback_state_;
AddBehaviour doubleclick_addmode_;
PlayBehaviour doubleclick_playmode_;
PlayBehaviour menu_playmode_;