casolorz
casolorz

Reputation: 9634

RemoteControlClient only shows play/pause toggle on lockscreen

I have a RemoteControlClient on my Android app and I gave it the following flags:

 myRemoteControlClient.setTransportControlFlags(
            RemoteControlClient.FLAG_KEY_MEDIA_PLAY |
            RemoteControlClient.FLAG_KEY_MEDIA_PAUSE |
            RemoteControlClient.FLAG_KEY_MEDIA_REWIND |
            RemoteControlClient.FLAG_KEY_MEDIA_FAST_FORWARD |
            RemoteControlClient.FLAG_KEY_MEDIA_STOP);

However when it shows on the lock screen I only see pause or play depending on whether I am playing or paused.

Is there no way to show the other controls?

Thank you.

EDIT: here is the rest of my code:

    ComponentName myEventReceiver = new ComponentName(getApplicationContext().getPackageName(), PlayingBroadcastReceiver.class.getName());
    myAudioManager =
            (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
    myAudioManager.registerMediaButtonEventReceiver(myEventReceiver);
    // build the PendingIntent for the remote control client
    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    mediaButtonIntent.setComponent(myEventReceiver);
    PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent, 0);
    // create and register the remote control client
    myRemoteControlClient = new RemoteControlClient(mediaPendingIntent);

    myRemoteControlClient.setTransportControlFlags(
            RemoteControlClient.FLAG_KEY_MEDIA_PLAY |
                    RemoteControlClient.FLAG_KEY_MEDIA_PAUSE |
                    RemoteControlClient.FLAG_KEY_MEDIA_REWIND | RemoteControlClient.FLAG_KEY_MEDIA_FAST_FORWARD |
                    RemoteControlClient.FLAG_KEY_MEDIA_STOP);
    myAudioManager.registerRemoteControlClient(myRemoteControlClient);


    myRemoteControlClient.editMetadata(true)
            .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, item.getTitle())

            .putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, item.getBitmap())

            .apply();
    setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
    //Request audio focus for playback
    int result = myAudioManager.requestAudioFocus(this,
            AudioManager.STREAM_MUSIC,
            AudioManager.AUDIOFOCUS_GAIN);

Upvotes: 3

Views: 1927

Answers (3)

bma350
bma350

Reputation: 1281

Use the FLAG_KEY_MEDIA_PLAY_PAUSE

oRemoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE);

And lie to the RemoteControlClient ;-)

Tell him the stream is buffering and it will show the stop button!

oRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_BUFFERING);

Cheers

Upvotes: 1

Jordan Ferr
Jordan Ferr

Reputation: 329

You can use this statement to show icons

myRemoteControlClient.setTransportControlFlags(
                        RemoteControlClient.FLAG_KEY_MEDIA_PLAY   |
                        RemoteControlClient.FLAG_KEY_MEDIA_PAUSE  |
                        RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS |
                        RemoteControlClient.FLAG_KEY_MEDIA_NEXT );

Upvotes: 0

mrbob
mrbob

Reputation: 66

The FLAG_KEY_MEDIA_STOP never shows stop because of bug in android as reported here: https://code.google.com/p/android/issues/detail?id=29920

I'm not sure if it is the support lib (are you using it?) or not that causes the fast_forward and rewind to not work. I can't get them to show either so I'm using next and previous instead. I't might also be that they are not visible in the lockscreen but might be usable through headsets and other remote controlers that implement them.

Upvotes: 1

Related Questions