Changed playlist to automatically scroll to current item in playlist on change.

This commit is contained in:
Felix Ableitner 2013-12-10 19:44:28 +01:00
parent 99f72ee862
commit 8a08fb00ec
2 changed files with 14 additions and 2 deletions

View file

@ -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;

View file

@ -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);
}
});
}