Media Session Compat not showing Lockscreen controls on Pre-Lollipop

前端 未结 3 1390
一个人的身影
一个人的身影 2021-01-30 07:14

I\'m using MediaSessionCompat from AppCompat Support Library Revision 22. And on Lollipop I\'m getting notification & also the background of lockscreen is the a

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-30 07:43

    While not strictly required for MediaSession, RemoteControlClient used on API14-19 devices, does require audio focus and it is 100% strongly recommended for all media playback.

    Adding lines such as:

    AudioManager audioManager = (AudioManager)
        getSystemService(Context.AUDIO_SERVICE);
    int result = audioManager.requestAudioFocus(this,
        AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
    if (result != AudioManager.AUDIOFOCUS_GAIN) {
        return; //Failed to gain audio focus
    }
    

    Before playing any media should gain audio focus and show controls.

提交回复
热议问题