Optimized prefetch of next track to happen way ahead of time to limit chance of gapless playback not working properly.

This commit is contained in:
casey 2016-06-17 22:17:55 -07:00
parent b9447a7bec
commit c7a9a93937
3 changed files with 15 additions and 12 deletions

View File

@ -297,7 +297,6 @@ void GaplessTransport::OnPlaybackStarted(Player* player) {
void GaplessTransport::OnPlaybackAlmostEnded(Player* player) {
this->SetNextCanStart(true);
this->RaiseStreamEvent(GaplessTransport::StreamAlmostDone, player);
{
boost::recursive_mutex::scoped_lock lock(this->stateMutex);
@ -308,10 +307,11 @@ void GaplessTransport::OnPlaybackAlmostEnded(Player* player) {
this->StartWithPlayer(this->nextPlayer);
}
}
this->RaiseStreamEvent(GaplessTransport::StreamAlmostDone, player);
}
void GaplessTransport::OnPlaybackFinished(Player* player) {
this->SetNextCanStart(true);
this->RaiseStreamEvent(GaplessTransport::StreamFinished, player);
bool stopped = false;
@ -345,7 +345,6 @@ void GaplessTransport::OnPlaybackFinished(Player* player) {
}
void GaplessTransport::OnPlaybackError(Player* player) {
this->SetNextCanStart(true);
this->RaiseStreamEvent(GaplessTransport::StreamError, player);
this->SetPlaybackState(GaplessTransport::PlaybackStopped);
DEFER(&GaplessTransport::RemoveActive, player);

View File

@ -67,19 +67,20 @@ PlaybackService::PlaybackService(LibraryPtr library, ITransport& transport)
this->nextIndex = NO_POSITION;
}
void PlaybackService::PrepareNextTrack() {
if (this->playlist.Count() > this->index + 1) {
if (this->nextIndex != this->index + 1) {
this->nextIndex = this->index + 1;
this->transport.PrepareNextTrack(URI_AT_INDEX(nextIndex));
}
}
}
void PlaybackService::ProcessMessage(IMessage &message) {
if (message.Type() == MESSAGE_STREAM_EVENT) {
int64 eventType = message.UserData1();
if (eventType == ITransport::StreamAlmostDone) {
if (this->playlist.Count() > this->index + 1) {
if (this->nextIndex != this->index + 1) {
this->nextIndex = this->index + 1;
this->transport.PrepareNextTrack(URI_AT_INDEX(nextIndex));
}
}
}
else if (eventType == ITransport::StreamPlaying) {
if (eventType == ITransport::StreamPlaying) {
if (this->nextIndex != NO_POSITION) {
this->index = this->nextIndex;
this->nextIndex = NO_POSITION;
@ -88,6 +89,8 @@ void PlaybackService::ProcessMessage(IMessage &message) {
if (this->index != NO_POSITION) {
this->TrackChanged(this->index, this->playlist.Get(this->index));
}
this->PrepareNextTrack();
}
}
else if (message.Type() == MESSAGE_PLAYBACK_EVENT) {

View File

@ -77,6 +77,7 @@ namespace musik {
private:
void OnStreamEvent(int eventType, std::string uri);
void OnPlaybackEvent(int eventType);
void PrepareNextTrack();
musik::core::LibraryPtr library;
musik::core::audio::ITransport& transport;