mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-02-19 21:20:52 +01:00
Fixes for lock screen controls and notification spontaneously
reappearing.
This commit is contained in:
parent
793f5b4464
commit
004493921c
@ -18,17 +18,29 @@
|
|||||||
*/
|
*/
|
||||||
package net.sourceforge.subsonic.androidapp.domain;
|
package net.sourceforge.subsonic.androidapp.domain;
|
||||||
|
|
||||||
|
import android.media.RemoteControlClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Sindre Mehus
|
* @author Sindre Mehus
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public enum PlayerState {
|
public enum PlayerState {
|
||||||
IDLE,
|
IDLE(RemoteControlClient.PLAYSTATE_STOPPED),
|
||||||
DOWNLOADING,
|
DOWNLOADING(RemoteControlClient.PLAYSTATE_BUFFERING),
|
||||||
PREPARING,
|
PREPARING(RemoteControlClient.PLAYSTATE_BUFFERING),
|
||||||
PREPARED,
|
PREPARED(RemoteControlClient.PLAYSTATE_STOPPED),
|
||||||
STARTED,
|
STARTED(RemoteControlClient.PLAYSTATE_PLAYING),
|
||||||
STOPPED,
|
STOPPED(RemoteControlClient.PLAYSTATE_STOPPED),
|
||||||
PAUSED,
|
PAUSED(RemoteControlClient.PLAYSTATE_PAUSED),
|
||||||
COMPLETED
|
COMPLETED(RemoteControlClient.PLAYSTATE_STOPPED);
|
||||||
|
|
||||||
|
private final int mRemoteControlClientPlayState;
|
||||||
|
|
||||||
|
private PlayerState(int playState) {
|
||||||
|
mRemoteControlClientPlayState = playState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRemoteControlClientPlayState() {
|
||||||
|
return mRemoteControlClientPlayState;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -760,19 +760,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
|
|||||||
RemoteControlHelper.registerRemoteControlClient(audioManager, remoteControlClientCompat);
|
RemoteControlHelper.registerRemoteControlClient(audioManager, remoteControlClientCompat);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (playerState)
|
remoteControlClientCompat.setPlaybackState(playerState.getRemoteControlClientPlayState());
|
||||||
{
|
|
||||||
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.setTransportControlFlags(
|
remoteControlClientCompat.setTransportControlFlags(
|
||||||
RemoteControlClient.FLAG_KEY_MEDIA_PLAY |
|
RemoteControlClient.FLAG_KEY_MEDIA_PLAY |
|
||||||
@ -800,6 +788,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
|
|||||||
remoteControlClientCompat
|
remoteControlClientCompat
|
||||||
.editMetadata(true)
|
.editMetadata(true)
|
||||||
.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, title)
|
.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, title)
|
||||||
|
.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, currentSong.getArtist())
|
||||||
.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, album)
|
.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, album)
|
||||||
.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, duration)
|
.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, duration)
|
||||||
.putBitmap(RemoteControlClientCompat.MetadataEditorCompat.METADATA_KEY_ARTWORK, bitmap)
|
.putBitmap(RemoteControlClientCompat.MetadataEditorCompat.METADATA_KEY_ARTWORK, bitmap)
|
||||||
@ -875,7 +864,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
|
|||||||
mp.start();
|
mp.start();
|
||||||
setPlayerState(STARTED);
|
setPlayerState(STARTED);
|
||||||
} else {
|
} else {
|
||||||
setPlayerState(PAUSED);
|
setPlayerState(STOPPED);
|
||||||
}
|
}
|
||||||
|
|
||||||
lifecycleSupport.serializeDownloadQueue();
|
lifecycleSupport.serializeDownloadQueue();
|
||||||
|
@ -200,6 +200,8 @@ public class DownloadServiceLifecycleSupport {
|
|||||||
|
|
||||||
// Work-around: Serialize again, as the restore() method creates a serialization without current playing info.
|
// Work-around: Serialize again, as the restore() method creates a serialization without current playing info.
|
||||||
serializeDownloadQueue();
|
serializeDownloadQueue();
|
||||||
|
|
||||||
|
downloadService.setPlayerState(PlayerState.STOPPED);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleKeyEvent(KeyEvent event) {
|
private void handleKeyEvent(KeyEvent event) {
|
||||||
@ -209,6 +211,8 @@ public class DownloadServiceLifecycleSupport {
|
|||||||
|
|
||||||
switch (event.getKeyCode()) {
|
switch (event.getKeyCode()) {
|
||||||
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
|
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
|
||||||
|
case KeyEvent.KEYCODE_MEDIA_PLAY:
|
||||||
|
case KeyEvent.KEYCODE_MEDIA_PAUSE:
|
||||||
case KeyEvent.KEYCODE_HEADSETHOOK:
|
case KeyEvent.KEYCODE_HEADSETHOOK:
|
||||||
downloadService.togglePlayPause();
|
downloadService.togglePlayPause();
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user