Fixed a bug where "PlaybackStopped" was getting triggered when it didn't

need to, leading to a slightly laggy UI in some cases.
This commit is contained in:
casey 2016-06-03 20:16:30 -07:00
parent b286d83c78
commit 15a181a281
2 changed files with 16 additions and 12 deletions

View File

@ -105,13 +105,16 @@ void Transport::StartWithPlayer(Player* newPlayer) {
boost::recursive_mutex::scoped_lock lock(this->stateMutex); boost::recursive_mutex::scoped_lock lock(this->stateMutex);
bool playingNext = (newPlayer == nextPlayer); bool playingNext = (newPlayer == nextPlayer);
if (newPlayer != nextPlayer) { if (newPlayer != nextPlayer) {
delete nextPlayer; delete nextPlayer;
} }
this->nextPlayer = NULL; this->nextPlayer = NULL;
this->Stop(playingNext); /* true = suppress stopped event */
/* first argument suppresses the "Stop" event from getting triggered,
the second param is used for gapless playback -- we won't stop the output
and will allow pending buffers to finish */
this->Stop(true, !playingNext);
this->SetNextCanStart(false); this->SetNextCanStart(false);
newPlayer->PlaybackStarted.connect(this, &Transport::OnPlaybackStarted); newPlayer->PlaybackStarted.connect(this, &Transport::OnPlaybackStarted);
@ -131,10 +134,10 @@ void Transport::StartWithPlayer(Player* newPlayer) {
} }
void Transport::Stop() { void Transport::Stop() {
this->Stop(false); this->Stop(false, true);
} }
void Transport::Stop(bool playingNext) { void Transport::Stop(bool suppressStopEvent, bool stopOutput) {
musik::debug::info(TAG, "stop"); musik::debug::info(TAG, "stop");
std::list<Player*> toDelete; std::list<Player*> toDelete;
@ -151,16 +154,17 @@ void Transport::Stop(bool playingNext) {
std::for_each(toDelete.begin(), toDelete.end(), stopPlayer); std::for_each(toDelete.begin(), toDelete.end(), stopPlayer);
DEFER(&Transport::DeletePlayers, toDelete); DEFER(&Transport::DeletePlayers, toDelete);
if (stopOutput) {
/* stopping the transport will stop any buffers that are currently in /* stopping the transport will stop any buffers that are currently in
flight. this makes the sound end immediately. */ flight. this makes the sound end immediately. */
if (!playingNext) {
this->output->Stop(); this->output->Stop();
} }
if (!suppressStopEvent) {
/* if we know we're starting another track immediately, suppress /* if we know we're starting another track immediately, suppress
the stop event. this functionality is not available to the public the stop event. this functionality is not available to the public
interface, it's an internal optimization */ interface, it's an internal optimization */
if (!playingNext) {
this->SetPlaybackState(PlaybackStopped); this->SetPlaybackState(PlaybackStopped);
} }
} }

View File

@ -84,7 +84,7 @@ namespace musik { namespace core { namespace audio {
private: private:
void StartWithPlayer(Player* player); void StartWithPlayer(Player* player);
void Stop(bool stopOutput); void Stop(bool suppressStopEvent, bool stopOutput);
void RemoveActive(Player* player); void RemoveActive(Player* player);
void DeletePlayers(std::list<Player*> players); void DeletePlayers(std::list<Player*> players);
void SetNextCanStart(bool nextCanStart); void SetNextCanStart(bool nextCanStart);