From 8a08fb00ec2db80ff790fee000437521302fd661 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Tue, 10 Dec 2013 19:44:28 +0100 Subject: [PATCH] Changed playlist to automatically scroll to current item in playlist on change. --- .../github/nutomic/controldlna/gui/RouteFragment.java | 11 ++++++++++- .../mediarouter/MediaRouterPlayService.java | 5 ++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/com/github/nutomic/controldlna/gui/RouteFragment.java b/src/com/github/nutomic/controldlna/gui/RouteFragment.java index 3c42e58..a8f3264 100644 --- a/src/com/github/nutomic/controldlna/gui/RouteFragment.java +++ b/src/com/github/nutomic/controldlna/gui/RouteFragment.java @@ -110,6 +110,7 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements mMediaRouterPlayService = (MediaRouterPlayServiceBinder) service; mMediaRouterPlayService.getService().setRouterFragment(RouteFragment.this); mPlaylistAdapter.addAll(mMediaRouterPlayService.getService().getPlaylist()); + receiveIsPlaying(mMediaRouterPlayService.getService().getCurrentTrack()); } public void onServiceDisconnected(ComponentName className) { @@ -447,9 +448,17 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements : "0" + Integer.toString(seconds)); } + /** + * Sent by MediaRouterPlayService when playback of a new track is started. + * + * @param track Index of the track in the playlist. + */ + public void receiveIsPlaying(int track) { + mListView.smoothScrollToPosition(track); + } + /** * Receives information from MediaRouterPlayService about playback status. - * TODO: doc */ public void receivePlaybackStatus(MediaItemStatus status) { int currentTime = (int) status.getContentPosition() / 1000; diff --git a/src/com/github/nutomic/controldlna/mediarouter/MediaRouterPlayService.java b/src/com/github/nutomic/controldlna/mediarouter/MediaRouterPlayService.java index af7ccea..d53fff7 100644 --- a/src/com/github/nutomic/controldlna/mediarouter/MediaRouterPlayService.java +++ b/src/com/github/nutomic/controldlna/mediarouter/MediaRouterPlayService.java @@ -84,7 +84,7 @@ public class MediaRouterPlayService extends Service { /** * The track that is currently being played. */ - private int mCurrentTrack; + private int mCurrentTrack = -1; private String mItemId; @@ -230,6 +230,9 @@ public class MediaRouterPlayService extends Service { new CreateNotificationTask().execute(mPlaylist.get(mCurrentTrack) .getFirstPropertyValue(DIDLObject.Property.UPNP.ALBUM_ART_URI.class)); + + if (mRouterFragment.get() != null) + mRouterFragment.get().receiveIsPlaying(mCurrentTrack); } }); }