use of android.media.RemoteControlClient in project Shuttle by timusus.
the class MusicService method setupMediaSession.
private void setupMediaSession() {
mediaSession = new MediaSessionCompat(this, "Shuttle", mediaButtonReceiverComponent, null);
mediaSession.setCallback(new MediaSessionCompat.Callback() {
@Override
public void onPause() {
pause();
pausedByTransientLossOfFocus = false;
}
@Override
public void onPlay() {
play();
}
@Override
public void onSeekTo(long pos) {
seekTo(pos);
}
@Override
public void onSkipToNext() {
gotoNext(true);
}
@Override
public void onSkipToPrevious() {
prev();
}
@Override
public void onStop() {
pause();
pausedByTransientLossOfFocus = false;
releaseServiceUiAndStop();
}
@Override
public boolean onMediaButtonEvent(Intent mediaButtonEvent) {
Log.e("MediaButtonReceiver", "OnMediaButtonEvent called");
MediaButtonIntentReceiver.MediaButtonReceiverHelper.onReceive(MusicService.this, mediaButtonEvent);
return true;
}
});
mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS | MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS);
// For some reason, MediaSessionCompat doesn't seem to pass all of the available 'actions' on as
// transport control flags for the RCC, so we do that manually
RemoteControlClient remoteControlClient = (RemoteControlClient) mediaSession.getRemoteControlClient();
if (remoteControlClient != null) {
remoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_STOP);
}
}
Aggregations