Sameer Sameer - 2 months ago 19x
Android Question

Media Control on Lock Screen like Google Play Music in android?

I had gone through Lock-screen Widget documentation, i implemented it but this is not what automatically place on main Lock Window. I searching for solution which provide Media Control over Main Lock-screen window (in Jelly Bean and above) like Google Play Music Application.

Have Look on Google Play Music Lock which obviously is not Lock Screen widget.

enter image description here


Have you checked RemoteControlClient? it is used for the Android Music Remote control even if the App is in Lock mode.(same like image you have attached)

Please check RemoteControlClient

Just call below method while you receiver command action for Play,Pause,Next and previous of the Song track.

  private void lockScreenControls() {

    // Use the media button APIs (if available) to register ourselves for media button
    // events

    MediaButtonHelper.registerMediaButtonEventReceiverCompat(mAudioManager, mMediaButtonReceiverComponent);
    // Use the remote control APIs (if available) to set the playback state
    if (mRemoteControlClientCompat == null) {
        Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
        mRemoteControlClientCompat = new RemoteControlClientCompat(PendingIntent.getBroadcast(this /*context*/,0 /*requestCode, ignored*/, intent /*intent*/, 0 /*flags*/));
            RemoteControlClient.FLAG_KEY_MEDIA_PAUSE |
            RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS |
            RemoteControlClient.FLAG_KEY_MEDIA_NEXT |

  //update remote controls
            .putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, "NombreArtista")
            .putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, "Titulo Album")
            .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, nombreCancion)
                    // TODO: fetch real item artwork
            .putBitmap(RemoteControlClientCompat.MetadataEditorCompat.METADATA_KEY_ARTWORK, getAlbumArt())

Please also check this developer app given for how to integrate RemoteControlClient: Random Music Player However UI for the RemoteControlClient deffer as per the device you can not updates its UI to your own but you have control to show and display the component and control of the Music app.

Hope this will help you. Please let me know if you are not getting for how to implement that lock screen control for the Music app.

Enjoy Coding. :)