When using the CrossfadeTransport, fade music out if stopped (or the app is exited).

This commit is contained in:
Casey Langen 2016-12-25 19:21:57 -08:00
parent 105a72457e
commit eb175cd66c
3 changed files with 18 additions and 3 deletions

View File

@ -61,6 +61,7 @@ CrossfadeTransport::CrossfadeTransport()
CrossfadeTransport::~CrossfadeTransport() {
this->Stop();
this->crossfader.Drain();
}
PlaybackState CrossfadeTransport::GetPlaybackState() {
@ -93,9 +94,8 @@ void CrossfadeTransport::ReloadOutput() {
void CrossfadeTransport::Stop() {
{
Lock lock(this->stateMutex);
this->crossfader.Stop();
this->active.Stop();
this->next.Stop();
this->active.Reset();
this->next.Reset();
}
this->SetPlaybackState(PlaybackStopped);

View File

@ -125,6 +125,18 @@ void Crossfader::Stop() {
this->contextList.clear();
}
void Crossfader::Drain() {
LOCK(this->contextListLock);
if (this->contextList.size()) {
for (FadeContextPtr context : this->contextList) {
context->direction = FadeOut;
}
this->drainCondition.wait(lock);
}
}
void Crossfader::OnPlayerDestroying(Player* player) {
if (player) {
LOCK(this->contextListLock);
@ -269,6 +281,7 @@ void Crossfader::ProcessMessage(IMessage &message) {
}
else {
this->Emptied();
this->drainCondition.notify_all();
}
}
break;

View File

@ -72,6 +72,7 @@ namespace musik { namespace core { namespace audio {
void Pause();
void Resume();
void Stop();
void Drain();
private:
void ThreadLoop();
@ -96,6 +97,7 @@ namespace musik { namespace core { namespace audio {
musik::core::runtime::MessageQueue messageQueue;
std::list<FadeContextPtr> contextList;
std::atomic<bool> quit, paused;
std::condition_variable_any drainCondition;
ITransport& transport;
};