本文介绍了在锁定屏幕像谷歌媒体控制播放音乐的机器人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过锁屏小工具文档走后,我实现它,但是这不是自动放置在主锁定窗口。我寻找解决方案,它提供媒体的控制主要锁定屏幕窗口(果冻豆及以上),如谷歌播放音乐的应用。

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.

推荐答案

你检查RemoteControlClient?它用于Android的音乐遥控器,即使在应用程序处于锁定状态。(你有附加同样喜欢的图像)

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)

请检查 RemoteControlClient

Please check RemoteControlClient

下面的方法,只要打电话,而你接收器播放命令采取行动,暂停,下一首,乐曲曲目previous。

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);
        intent.setComponent(mMediaButtonReceiverComponent);
        mRemoteControlClientCompat = new RemoteControlClientCompat(PendingIntent.getBroadcast(this /*context*/,0 /*requestCode, ignored*/, intent /*intent*/, 0 /*flags*/));
        RemoteControlHelper.registerRemoteControlClient(mAudioManager,mRemoteControlClientCompat);
    }
    mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
    mRemoteControlClientCompat.setTransportControlFlags(
            RemoteControlClient.FLAG_KEY_MEDIA_PAUSE |
            RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS |
            RemoteControlClient.FLAG_KEY_MEDIA_NEXT |
            RemoteControlClient.FLAG_KEY_MEDIA_STOP);

  //update remote controls
    mRemoteControlClientCompat.editMetadata(true)
            .putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, "NombreArtista")
            .putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, "Titulo Album")
            .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, nombreCancion)
            //.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION,playingItem.getDuration())
                    // TODO: fetch real item artwork
            .putBitmap(RemoteControlClientCompat.MetadataEditorCompat.METADATA_KEY_ARTWORK, getAlbumArt())
            .apply();
    }
}

请还检查给出了如何整合RemoteControlClient这个开发应用程序: Random音乐播放器 但是用户界面的RemoteControlClient deffer根据设备不能更新其用户界面以自己的,但你可以控制显示和显示的音乐应用程序的组件和控制。

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.

享受编码。 :)

这篇关于在锁定屏幕像谷歌媒体控制播放音乐的机器人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 19:15