diff --git a/src/net/sourceforge/subsonic/androidapp/domain/PlayerState.java b/src/net/sourceforge/subsonic/androidapp/domain/PlayerState.java index c9e87426..daa34535 100644 --- a/src/net/sourceforge/subsonic/androidapp/domain/PlayerState.java +++ b/src/net/sourceforge/subsonic/androidapp/domain/PlayerState.java @@ -18,17 +18,29 @@ */ package net.sourceforge.subsonic.androidapp.domain; +import android.media.RemoteControlClient; + /** * @author Sindre Mehus * @version $Id$ */ public enum PlayerState { - IDLE, - DOWNLOADING, - PREPARING, - PREPARED, - STARTED, - STOPPED, - PAUSED, - COMPLETED + IDLE(RemoteControlClient.PLAYSTATE_STOPPED), + DOWNLOADING(RemoteControlClient.PLAYSTATE_BUFFERING), + PREPARING(RemoteControlClient.PLAYSTATE_BUFFERING), + PREPARED(RemoteControlClient.PLAYSTATE_STOPPED), + STARTED(RemoteControlClient.PLAYSTATE_PLAYING), + STOPPED(RemoteControlClient.PLAYSTATE_STOPPED), + PAUSED(RemoteControlClient.PLAYSTATE_PAUSED), + COMPLETED(RemoteControlClient.PLAYSTATE_STOPPED); + + private final int mRemoteControlClientPlayState; + + private PlayerState(int playState) { + mRemoteControlClientPlayState = playState; + } + + public int getRemoteControlClientPlayState() { + return mRemoteControlClientPlayState; + } } diff --git a/src/net/sourceforge/subsonic/androidapp/service/DownloadServiceImpl.java b/src/net/sourceforge/subsonic/androidapp/service/DownloadServiceImpl.java index c54df363..8cdb73c3 100644 --- a/src/net/sourceforge/subsonic/androidapp/service/DownloadServiceImpl.java +++ b/src/net/sourceforge/subsonic/androidapp/service/DownloadServiceImpl.java @@ -760,19 +760,7 @@ public class DownloadServiceImpl extends Service implements DownloadService { RemoteControlHelper.registerRemoteControlClient(audioManager, remoteControlClientCompat); } - switch (playerState) - { - case STARTED: - remoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); - break; - case PAUSED: - remoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED); - break; - case IDLE: - case STOPPED: - remoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED); - break; - } + remoteControlClientCompat.setPlaybackState(playerState.getRemoteControlClientPlayState()); remoteControlClientCompat.setTransportControlFlags( RemoteControlClient.FLAG_KEY_MEDIA_PLAY | @@ -800,6 +788,7 @@ public class DownloadServiceImpl extends Service implements DownloadService { remoteControlClientCompat .editMetadata(true) .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, title) + .putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, currentSong.getArtist()) .putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, album) .putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, duration) .putBitmap(RemoteControlClientCompat.MetadataEditorCompat.METADATA_KEY_ARTWORK, bitmap) @@ -875,7 +864,7 @@ public class DownloadServiceImpl extends Service implements DownloadService { mp.start(); setPlayerState(STARTED); } else { - setPlayerState(PAUSED); + setPlayerState(STOPPED); } lifecycleSupport.serializeDownloadQueue(); diff --git a/src/net/sourceforge/subsonic/androidapp/service/DownloadServiceLifecycleSupport.java b/src/net/sourceforge/subsonic/androidapp/service/DownloadServiceLifecycleSupport.java index aec39245..3ca60a8f 100644 --- a/src/net/sourceforge/subsonic/androidapp/service/DownloadServiceLifecycleSupport.java +++ b/src/net/sourceforge/subsonic/androidapp/service/DownloadServiceLifecycleSupport.java @@ -200,6 +200,8 @@ public class DownloadServiceLifecycleSupport { // Work-around: Serialize again, as the restore() method creates a serialization without current playing info. serializeDownloadQueue(); + + downloadService.setPlayerState(PlayerState.STOPPED); } private void handleKeyEvent(KeyEvent event) { @@ -209,6 +211,8 @@ public class DownloadServiceLifecycleSupport { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: + case KeyEvent.KEYCODE_MEDIA_PLAY: + case KeyEvent.KEYCODE_MEDIA_PAUSE: case KeyEvent.KEYCODE_HEADSETHOOK: downloadService.togglePlayPause(); break;