diff --git a/src/core/audio/CrossfadeTransport.cpp b/src/core/audio/CrossfadeTransport.cpp index 6fff0ed73..d34e92da5 100644 --- a/src/core/audio/CrossfadeTransport.cpp +++ b/src/core/audio/CrossfadeTransport.cpp @@ -358,6 +358,11 @@ void CrossfadeTransport::PlayerContext::Reset( Crossfader::FadeOut, CROSSFADE_DURATION_MS); } + else { + /* if we're being started with a new URL and we can't fade, + drain the current instance! */ + player->Destroy(url.size() ? Player::NoDrain : Player::Drain); + } } this->canFade = this->started = false; diff --git a/src/core/audio/Player.cpp b/src/core/audio/Player.cpp index 2c7a61516..544af82fc 100644 --- a/src/core/audio/Player.cpp +++ b/src/core/audio/Player.cpp @@ -109,16 +109,16 @@ namespace musik { Player* Player::Create( const std::string &url, std::shared_ptr output, - FinishMode finishMode, + DestroyMode destroyMode, EventListener *listener) { - return new Player(url, output, finishMode, listener); + return new Player(url, output, destroyMode, listener); } Player::Player( const std::string &url, std::shared_ptr output, - FinishMode finishMode, + DestroyMode destroyMode, EventListener *listener) : state(Player::Precache) , url(url) @@ -126,7 +126,7 @@ Player::Player( , output(output) , notifiedStarted(false) , setPosition(-1) -, finishMode(finishMode) +, destroyMode(destroyMode) , fftContext(nullptr) { musik::debug::info(TAG, "new instance created"); @@ -174,6 +174,11 @@ void Player::Destroy() { } } +void Player::Destroy(DestroyMode mode) { + this->destroyMode = mode; + this->Destroy(); +} + void Player::Detach(EventListener* listener) { if (listener) { std::unique_lock lock(this->listenerMutex); @@ -373,7 +378,7 @@ void musik::core::audio::playerThreadLoop(Player* player) { } /* buffers have been written, wait for the output to play them all */ - if (player->finishMode == Player::Drain) { + if (player->destroyMode == Player::Drain) { player->output->Drain(); } diff --git a/src/core/audio/Player.h b/src/core/audio/Player.h index de52ec973..fb068a39e 100644 --- a/src/core/audio/Player.h +++ b/src/core/audio/Player.h @@ -52,7 +52,7 @@ namespace musik { namespace core { namespace audio { class Player : public musik::core::sdk::IBufferProvider { public: - enum FinishMode { Drain, NoDrain }; + enum DestroyMode { Drain, NoDrain }; struct EventListener { virtual void OnPlayerPrepared(Player *player) { } @@ -67,7 +67,7 @@ namespace musik { namespace core { namespace audio { static Player* Create( const std::string &url, std::shared_ptr output, - FinishMode finishMode, + DestroyMode destroyMode, EventListener *listener); virtual void OnBufferProcessed(musik::core::sdk::IBuffer *buffer); @@ -77,6 +77,7 @@ namespace musik { namespace core { namespace audio { void Play(); void Destroy(); + void Destroy(DestroyMode mode); double GetPosition(); void SetPosition(double seconds); @@ -92,7 +93,7 @@ namespace musik { namespace core { namespace audio { Player( const std::string &url, std::shared_ptr output, - FinishMode finishMode, + DestroyMode finishMode, EventListener *listener); virtual ~Player(); @@ -148,7 +149,7 @@ namespace musik { namespace core { namespace audio { bool notifiedStarted; float* spectrum; uint64 samplesWritten; - FinishMode finishMode; + DestroyMode destroyMode; FftContext* fftContext; };