Round out session resumption: remember and restore the play head.

This commit is contained in:
casey langen 2018-02-18 15:02:05 -08:00
parent 8550e62b1d
commit 177cf1851e
7 changed files with 11 additions and 11 deletions

View File

@ -180,10 +180,6 @@ void CrossfadeTransport::SetPosition(double seconds) {
}
}
if (this->state == PlaybackPaused) {
SetPlaybackState(PlaybackPlaying);
}
if (this->active.player) {
this->TimeChanged(seconds);
}

View File

@ -244,10 +244,6 @@ void GaplessTransport::SetPosition(double seconds) {
}
}
if (this->state == PlaybackPaused) {
SetPlaybackState(PlaybackPlaying);
}
if (this->activePlayer) {
this->TimeChanged(seconds);
}

View File

@ -691,8 +691,11 @@ void PlaybackService::Play(size_t index) {
this->PlayAt(index, ITransport::StartMode::Immediate);
}
void PlaybackService::Prepare(size_t index) {
void PlaybackService::Prepare(size_t index, double position) {
this->PlayAt(index, ITransport::StartMode::Wait);
if (position > 0.0) {
this->transport.SetPosition(position);
}
}
size_t PlaybackService::GetIndex() {

View File

@ -115,7 +115,7 @@ namespace musik { namespace core { namespace audio {
concrete data types with known optimizations */
musik::core::audio::ITransport& GetTransport() { return this->transport; }
void Play(const musik::core::TrackList& tracks, size_t index);
void Prepare(size_t index);
void Prepare(size_t index, double position = 0.0f);
void CopyTo(musik::core::TrackList& target);
void CopyFrom(const musik::core::TrackList& source);
musik::core::TrackPtr GetTrackAtIndex(size_t index);

View File

@ -98,7 +98,8 @@ void NowPlayingLayout::LoadLastSession() {
int index = this->prefs->GetInt(keys::LastPlayQueueIndex, -1);
if (index >= 0) {
this->playback.Prepare(index);
double time = this->prefs->GetDouble(keys::LastPlayQueueTime, 0.0f);
this->playback.Prepare(index, time);
}
}
@ -106,9 +107,11 @@ void NowPlayingLayout::SaveSession() {
if (this->prefs->GetBool(keys::SaveSessionOnExit, false)) {
if (playback.GetPlaybackState() != sdk::PlaybackStopped) {
this->prefs->SetInt(keys::LastPlayQueueIndex, (int) playback.GetIndex());
this->prefs->SetDouble(keys::LastPlayQueueTime, playback.GetPosition());
}
else {
this->prefs->SetInt(keys::LastPlayQueueIndex, -1);
this->prefs->SetDouble(keys::LastPlayQueueTime, 0.0f);
}
auto query = std::shared_ptr<PersistedPlayQueueQuery>(

View File

@ -53,6 +53,7 @@ namespace musik { namespace cube { namespace prefs {
const std::string keys::LastCategoryFilter = "LastCategoryFilter";
const std::string keys::LastTrackFilter = "LastTrackFilter";
const std::string keys::LastPlayQueueIndex = "LastPlayQueueIndex";
const std::string keys::LastPlayQueueTime = "LastPlayQueueTime";
} } }

View File

@ -55,6 +55,7 @@ namespace musik { namespace cube { namespace prefs {
extern const std::string LastCategoryFilter;
extern const std::string LastTrackFilter;
extern const std::string LastPlayQueueIndex;
extern const std::string LastPlayQueueTime;
}