Fixes for lock screen controls and notification spontaneously

reappearing.
This commit is contained in:
Brian Rodgers 2013-02-19 23:53:21 -06:00
parent 793f5b4464
commit 004493921c
3 changed files with 27 additions and 22 deletions

View File

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

View File

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

View File

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