How to use the new MediaSession class to receive media button presses on Android 5.x?

前端 未结 2 892
小鲜肉
小鲜肉 2020-12-14 23:04

I’m attempting to receive media button presses using the new MediaSession class and so far I’ve been unsuccessful. Has anyone managed to receive them using the new class?

2条回答
  •  被撕碎了的回忆
    2020-12-14 23:52

    onMediaButtonEvent(..) has a default implementation in MediaSession.Callback. In your code if you call super.onMediaButtonEvent(..), then depending on the keycodes the correct callback namely onPlay(), onPause() will be called.

    You can take a look at the default implementation in MediaSession.java

提交回复
热议问题