- Updated SDK version, added IPlaybackService::GetPlayingTrack()

- Added PlaybackService::GetPlayingTrack and PlaybackService::GetPlaying to get
  an IRetainedTrack or TrackPtr to the currently playing track, respectively.
- Fixed PlaybackService::CopyFrom() to correctly discover the playing track and
  queue up the next one, if applicable. Else queue up the first track
- Fixed NowPlayingLayout to use PlaybackService::GetPlaying() to resolve the
  currently playing track.
This commit is contained in:
Casey Langen 2017-01-26 08:46:06 -08:00
parent e778c6034d
commit 1f0139c5cd
5 changed files with 30 additions and 2 deletions

View File

@ -332,6 +332,7 @@ void PlaybackService::ProcessMessage(IMessage &message) {
}
void PlaybackService::OnTrackChanged(size_t pos, TrackPtr track) {
this->playingTrack = track;
this->TrackChanged(this->index, track);
for (auto it = remotes.begin(); it != remotes.end(); it++) {
@ -434,7 +435,15 @@ void PlaybackService::CopyTo(TrackList& target) {
void PlaybackService::CopyFrom(TrackList& source) {
std::unique_lock<std::recursive_mutex> lock(this->playlistMutex);
this->playlist.CopyFrom(source);
this->index = NO_POSITION;
this->nextIndex = NO_POSITION;
if (this->playingTrack) {
this->index = playlist.IndexOf(this->playingTrack->Id());
POST(this, MESSAGE_PREPARE_NEXT_TRACK, NO_POSITION, 0);
}
}
void PlaybackService::Play(size_t index) {
@ -524,6 +533,21 @@ IRetainedTrack* PlaybackService::GetTrack(size_t index) {
return nullptr;
}
IRetainedTrack* PlaybackService::GetPlayingTrack() {
std::unique_lock<std::recursive_mutex> lock(this->playlistMutex);
if (this->playingTrack) {
return new RetainedTrack(this->playingTrack);
}
return nullptr;
}
TrackPtr PlaybackService::GetPlaying() {
std::unique_lock<std::recursive_mutex> lock(this->playlistMutex);
return this->playingTrack;
}
TrackPtr PlaybackService::GetTrackAtIndex(size_t index) {
std::unique_lock<std::recursive_mutex> lock(this->playlistMutex);

View File

@ -98,6 +98,7 @@ namespace musik { namespace core { namespace audio {
virtual void SetPosition(double seconds);
virtual double GetDuration();
virtual musik::core::sdk::IRetainedTrack* GetTrack(size_t index);
virtual musik::core::sdk::IRetainedTrack* GetPlayingTrack();
/* app-specific implementation */
musik::core::audio::ITransport& GetTransport() { return this->transport; }
@ -105,6 +106,7 @@ namespace musik { namespace core { namespace audio {
void CopyTo(musik::core::TrackList& target);
void CopyFrom(musik::core::TrackList& source);
musik::core::TrackPtr GetTrackAtIndex(size_t index);
musik::core::TrackPtr GetPlaying();
/* required to make changes to the playlist. this little data structure
privately owns a lock to the internal data structure and will release
@ -163,6 +165,7 @@ namespace musik { namespace core { namespace audio {
std::vector<std::shared_ptr<musik::core::sdk::IPlaybackRemote > > remotes;
std::shared_ptr<musik::core::Preferences> prefs;
musik::core::TrackPtr playingTrack;
musik::core::ILibraryPtr library;
musik::core::audio::ITransport& transport;

View File

@ -70,6 +70,7 @@ namespace musik { namespace core { namespace sdk {
virtual size_t Count() = 0;
virtual IRetainedTrack* GetTrack(size_t index) = 0;
virtual IRetainedTrack* GetPlayingTrack() = 0; /* sdk v2 */
};
} } }

View File

@ -78,5 +78,5 @@ namespace musik {
ChannelSideRight = 256
};
static const int SdkVersion = 1;
static const int SdkVersion = 2;
} } }

View File

@ -92,7 +92,7 @@ int64 NowPlayingLayout::RowDecorator(musik::core::TrackPtr track, size_t index)
size_t playingIndex = playback.GetIndex();
if (index == playingIndex) {
TrackPtr playing = playback.GetTrackAtIndex(playingIndex);
TrackPtr playing = playback.GetPlaying();
if (playing &&
playing->Id() == track->Id() &&