MediaSessionCompat未在API上显示RemoteControlClient<棒糖

时间:2015-06-23 18:08:53

标签: android android-mediaplayer android-support-library

我在一个使用支持22.2.0的应用程序中使用MediaSessionCompat,它在Lollipop上工作得很好,但它不是在Lollipop版本(使用KitKat设备测试)中为锁屏控制创建RemoteControlClient。

    PendingIntent pi = PendingIntent.getBroadcast(this, 99, new Intent(ACTION_MEDIA_BUTTONS), PendingIntent.FLAG_UPDATE_CURRENT);
    ComponentName receiver = new ComponentName(getPackageName(), MediaControlReceiver.class.getName());
    mediaSession = new MediaSessionCompat(this, "PlayerService", receiver, pi);
    mediaSession.setCallback(new MediaSessionCallbacks());
    mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    controller = mediaSession.getController();

我在我的清单中设置了一个BroadcastReceiver来收听我正在加入PendingIntent的MEDIA_BUTTON动作,一切看起来都像是设置了,所以我不确定为什么它没有显示RemoteControl在KitKat下方的锁屏上。我错过了什么?

   <receiver android:name=".ui.audiobook.player.RemoteControlReceiver">
        <intent-filter>
            <action android:name="com.app.MEDIA_BUTTON" />
        </intent-filter>
    </receiver>

1 个答案:

答案 0 :(得分:0)

想通了我忘了在MediaSession中设置PlayState,这使得RemoteControlClient出现在没有运行Lollipop的设备上。