I am using a Videoview
to play an animation video in the loop. I noticed that whenever the video is playing if any other music app is playing audio and I click on headset buttons(pause/play)
, the media button events are not dispatched to the music playing app. Instead, it is dispatched to my ExampleService
which extends from MediaBrowserServiceCompat
. Videoview
is stealing those media button events. I am using even AudioManager.AUDIO_FOCUS_NONE
.
I noticed when my app opens and video plays, I can see a log in the stack trace that
D/MediaSessionService: Media button session is changed to com.example.mediasessiontest/ExampleService (userId=0)
Is there a way to play video without requesting for Mediabutton
event?
- If I don't play video in my app, headset events are correctly routed to the app which was playing music
- This is happening only on
Android 8 and 9
. Works fine onAndroid 10
. Tried even
Surfaceview
withMediaplayer
to play video. But observed the same issue.private val VIDEO_BASE_PATH = "android.resource://" videoView.setAudioFocusRequest(AudioManager.AUDIOFOCUS_NONE) videoView.setMediaController(null) videoView.setVideoPath(VIDEO_BASE_PATH + packageName + "/" + R.raw.test_video) videoView.setOnPreparedListener { player -> player.isLooping = true player.start() //This causes the media button sesssion to be changed }
Tried using
Surfaceview
withMediaplayer
as well. But same result. Looks like a bug in OS8 and 9
?