RemoteControlClient仅显示锁定屏幕上的播放/暂停切换

时间:2014-01-30 01:47:53

标签: android

我的Android应用程序上有一个RemoteControlClient,我给它了以下标志:

 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);

然而,当它在锁定屏幕上显示时,我只会看到暂停或播放,具体取决于我是在播放还是暂停。

是否无法显示其他控件?

谢谢。

编辑:这是我的其余代码:

    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);

3 个答案:

答案 0 :(得分:1)

FLAG_KEY_MEDIA_STOP永远不会显示停止,因为在此处报告了android中的错误:https://code.google.com/p/android/issues/detail?id=29920

我不确定它是否是支持库(你使用它吗?)或者不会导致fast_forward和倒带不起作用。 我无法让他们显示,所以我正在使用next和previous。我也可能不会在锁屏中看到它们,但可以通过耳机和其他实现它们的远程控制器使用它们。

答案 1 :(得分:1)

使用FLAG_KEY_MEDIA_PLAY_PAUSE

oRemoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE);

说谎RemoteControlClient; - )

告诉他流正在缓冲,它会显示停止按钮!

oRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_BUFFERING);

干杯

答案 2 :(得分:0)

您可以使用此语句来显示图标

myRemoteControlClient.setTransportControlFlags(
                        RemoteControlClient.FLAG_KEY_MEDIA_PLAY   |
                        RemoteControlClient.FLAG_KEY_MEDIA_PAUSE  |
                        RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS |
                        RemoteControlClient.FLAG_KEY_MEDIA_NEXT );
相关问题