Added IPlaybackService::ReloadOutput(). Playback is no longer reset when

the selected output device changes -- it now picks up where it left off.
This commit is contained in:
casey langen 2018-01-13 21:40:56 -08:00
parent c451c6a5be
commit b0cfc893ff
6 changed files with 30 additions and 4 deletions

View File

@ -580,6 +580,25 @@ void PlaybackService::Play(const musik::core::sdk::ITrackList* source, size_t in
} }
} }
void PlaybackService::ReloadOutput() {
auto state = this->GetPlaybackState();
auto index = this->GetIndex();
double time = this->GetPosition();
this->Stop();
this->transport.ReloadOutput();
if (index != NO_POSITION) {
this->Play(index);
if (time > 0.0f) {
this->transport.SetPosition(time);
}
if (state == PlaybackPaused) {
this->transport.Pause();
}
}
}
void PlaybackService::CopyTo(TrackList& target) { void PlaybackService::CopyTo(TrackList& target) {
std::unique_lock<std::recursive_mutex> lock(this->playlistMutex); std::unique_lock<std::recursive_mutex> lock(this->playlistMutex);
target.CopyFrom(this->playlist); target.CopyFrom(this->playlist);

View File

@ -105,6 +105,7 @@ namespace musik { namespace core { namespace audio {
virtual musik::core::sdk::ITrackListEditor* EditPlaylist() override; virtual musik::core::sdk::ITrackListEditor* EditPlaylist() override;
virtual musik::core::sdk::TimeChangeMode GetTimeChangeMode() override; virtual musik::core::sdk::TimeChangeMode GetTimeChangeMode() override;
virtual void SetTimeChangeMode(musik::core::sdk::TimeChangeMode) override; virtual void SetTimeChangeMode(musik::core::sdk::TimeChangeMode) override;
virtual void ReloadOutput() override;
/* TODO: include in SDK? */ /* TODO: include in SDK? */
virtual bool HotSwap(const TrackList& source, size_t index = 0); virtual bool HotSwap(const TrackList& source, size_t index = 0);

View File

@ -232,7 +232,10 @@ void Player::SetPosition(double seconds) {
std::unique_lock<std::mutex> queueLock(this->queueMutex); std::unique_lock<std::mutex> queueLock(this->queueMutex);
if (this->stream) { if (this->stream) {
seconds = std::min(this->stream->GetDuration(), seconds); auto duration = this->stream->GetDuration();
if (duration > 0.0f) {
seconds = std::min(duration, seconds);
}
} }
this->seekToPosition.store(std::max(0.0, seconds)); this->seekToPosition.store(std::max(0.0, seconds));

View File

@ -85,6 +85,9 @@ namespace musik { namespace core { namespace sdk {
/* sdk v5 */ /* sdk v5 */
virtual musik::core::sdk::TimeChangeMode GetTimeChangeMode() = 0; virtual musik::core::sdk::TimeChangeMode GetTimeChangeMode() = 0;
virtual void SetTimeChangeMode(musik::core::sdk::TimeChangeMode) = 0; virtual void SetTimeChangeMode(musik::core::sdk::TimeChangeMode) = 0;
/* sdk v13 */
virtual void ReloadOutput() = 0;
}; };
} } } } } }

View File

@ -134,5 +134,5 @@ namespace musik {
static const char* ExternalId = "external_id"; static const char* ExternalId = "external_id";
} }
static const int SdkVersion = 12; static const int SdkVersion = 13;
} } } } } }

View File

@ -207,7 +207,7 @@ void SettingsLayout::OnOutputDriverDropdownActivated(cursespp::TextLabel* label)
if (currentName != newName) { if (currentName != newName) {
this->LoadPreferences(); this->LoadPreferences();
this->transport.ReloadOutput(); this->playback.ReloadOutput();
} }
}); });
} }
@ -218,7 +218,7 @@ void SettingsLayout::OnOutputDeviceDropdownActivated(cursespp::TextLabel* label)
std::string newName = getOutputDeviceName(); std::string newName = getOutputDeviceName();
if (currentName != newName) { if (currentName != newName) {
this->LoadPreferences(); this->LoadPreferences();
this->transport.ReloadOutput(); this->playback.ReloadOutput();
} }
}); });
} }