So I'm using the following code in attempt to show metadata on Bluetooth AVRCP-Compatible devices, but haven't had any luck so far.
No controls are appearing on the lockscreen, which leads me to believe that the RemoteControlClient` isn't working as expected.
AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
ComponentName rec = new ComponentName(getPackageName(), MediaButtonReceiver.class.getName());
mAudioManager.registerMediaButtonEventReceiver(rec);
Intent i = new Intent(Intent.ACTION_MEDIA_BUTTON);
i.setComponent(rec);
PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, 0);
RemoteControlClient mRemoteControlClient = new RemoteControlClient(pi);
mAudioManager.registerRemoteControlClient(mRemoteControlClient);
int flags = RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS
| RemoteControlClient.FLAG_KEY_MEDIA_NEXT
| RemoteControlClient.FLAG_KEY_MEDIA_PLAY
| RemoteControlClient.FLAG_KEY_MEDIA_PAUSE
| RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE
| RemoteControlClient.FLAG_KEY_MEDIA_STOP;
mRemoteControlClient.setTransportControlFlags(flags);
mAudioManager.requestAudioFocus(null, AudioManager.STREAM_MUSIC,
AudioManager.AUDIOFOCUS_GAIN);
RemoteControlClient.MetadataEditor mEditor = mRemoteControlClient.editMetadata(true);
mEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, "RCC Artist");
mEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, "RCC Title");
mEditor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, "RCC Album");
mEditor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, 6039000);
mEditor.apply();
mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
I am executing this code when a button is pressed.
Then
RemoteControlClient
will not work.Correct. Quoting the documentation: