Add playback duration to lockscreen controls for 4.3+

This commit is contained in:
Joshua Bahnsen 2013-12-31 00:42:48 -07:00
parent be1f907024
commit 9e302b77e5

View File

@ -1450,10 +1450,24 @@ public class DownloadServiceImpl extends Service implements DownloadService
switch (playerState) switch (playerState)
{ {
case STARTED: case STARTED:
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2)
{
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
}
else
{
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING, getPlayerPosition(), 1);
}
break; break;
case PAUSED: case PAUSED:
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2)
{
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED); remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
}
else
{
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED, getPlayerPosition(), 1);
}
break; break;
case DOWNLOADING: case DOWNLOADING:
case PREPARING: case PREPARING:
@ -1463,9 +1477,11 @@ public class DownloadServiceImpl extends Service implements DownloadService
case COMPLETED: case COMPLETED:
case PREPARED: case PREPARED:
case STOPPED: case STOPPED:
default:
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED); remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
break; break;
default:
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
break;
} }
try try
@ -1486,7 +1502,7 @@ public class DownloadServiceImpl extends Service implements DownloadService
String artist = currentSong.getArtist(); String artist = currentSong.getArtist();
String album = currentSong.getAlbum(); String album = currentSong.getAlbum();
String title = String.format("%s - %s", artist, currentSong.getTitle()); String title = String.format("%s - %s", artist, currentSong.getTitle());
Integer duration = currentSong.getDuration(); Long duration = Long.valueOf(currentSong.getDuration() * 1000);
// Update the remote controls // Update the remote controls
remoteControlClient.editMetadata(true).putString(MediaMetadataRetriever.METADATA_KEY_TITLE, title).putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, artist).putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, album).apply(); remoteControlClient.editMetadata(true).putString(MediaMetadataRetriever.METADATA_KEY_TITLE, title).putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, artist).putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, album).apply();