Media3 play next / play previous
BejanCorneliu opened this issue · comments
Version
Media3 1.3.1
More version details
No response
Devices that reproduce the issue
Pixel 8 Pro,
Samsung S21,
Xiaomi Redmi note 11 pro
pixel1 SmartWatch
huawei FreeBuds 2,
Crusher ANC 2
Devices that do not reproduce the issue
No response
Reproducible in the demo app?
Not tested
Reproduction steps
In my app i use media3 in MediaSessionService where i start my ExoPlayer instance.
I use :
- ForwardingPlayer to set/add commands.
- MediaSession.Callback to override onMediaButtonEvent() and intercept KEYCODE_MEDIA_NEXT / KEYCODE_MEDIA_PREVIOUS ( we use custom streams with DRM license and i need to intercept to set by code the next stream)
Scenario 1 :
a) In my main test i use : Pixel 8 Pro + Pixel 1 smartWatch + Huawei FreeBuds2
b) on the next 2 examples i set only 1 media item on startup
Example 1 :
if i remove COMMAND_SEEK_TO_NEXT and COMMAND_SEEK_TO_PREVIOUS ( by using ForwardingPlayer ) :
- no play next/prev buttons on media3 notification on my phone
- play next/prev buttons on my smartwatch are disable
- but if i use next/prev from my huawei freeBuds2 -> i can intercept action in onMediaButtonEvent()
==> i was hopping not to get event play netx/prev on onMediaButtonEvent() ( but not this is my problem)
Example 2 :
If i add COMMAND_SEEK_TO_NEXT and COMMAND_SEEK_TO_PREVIOUS :
- i get play next/prev buttons on media3 notification on my phone but when i press them it seems to reload my stream and i don't get any event triggered in onMediaButtonEvent()
- play next/prev buttons on my smartwatch are enabled and i get expected event on onMediaButtonEvent()
- play next/prev actions from my huawei freeBuds2 works like above and now as expected
The problem => i was hopping after i add those 2 media commands that works fine on my pixel smartWatch, to work the same from my media3 notification on my phone
Scenario 2 :
a) In my main test i use : Pixel 8 Pro + Pixel 1 smartWatch + Huawei FreeBuds2
b) on the next example i set 3 media items ; First one as test hardcpded stream (to have and simulate "prev" action ), second one is the real stream that start playing and third one as fake media item to simulate "next" (startIndex 1 , startPositionMs 0 )
Example 1 :
if i add COMMAND_SEEK_TO_NEXT and COMMAND_SEEK_TO_PREVIOUS ( by using ForwardingPlayer ) :
-> now i can play next/prev from any above devices but i don't get any prev/next event on onMediaButtonEvent() ( to be able to intercept and prepare the next/prev stream ). It plays (next/prev) from the mediaItem lists where i hardcoded 2 streams
Obs:
When i receive events on onMediaButtonEvent i get those triggered by play/next action from divices as : KeyEvent.KEYCODE_MEDIA_NEXT or KeyEvent.KEYCODE_MEDIA_PREVIOUS
What commands to set to be able to intercept them as play next/previous actions sended from any of my devices ( phone - media3 notification, smartWatch or headphones in my onMediaButtonEvent() overide function from MediaSession.Callback implementation ?
Or
Is there any other solution to play a stream, still have prev/next action , intercept those action to prepeare the next/prev stream
Thanks
Expected result
By using ForwardingPlayer and added COMMAND_SEEK_TO_NEXT and COMMAND_SEEK_TO_PREVIOUS i was hopping to intercept play next/prev from any of my devices ( phone, headphones or smartwatch) the same in any
Actual result
By using ForwardingPlayer and added COMMAND_SEEK_TO_NEXT and COMMAND_SEEK_TO_PREVIOUS i can intercept play next/prev only from headphones or smartwatch and kind of stream reload ( i think ) from media 3 notification
Media
any media
Bug Report
- You will email the zip file produced by
adb bugreport
to android-media-github@google.com after filing this issue.
Thanks for your question.
That sounds not right to me actually. The intention of the library is to eventually route all these commands to the player.
So I don't think you need/should override onMediaButtonEvent
. Instead, the default implementation will dispatch the key event to Player.seekToNext
or Player.seekToPrevious
respectively. The forwarding player isn't bypassed and that's where you should await commands for interception.
There is a test case that asserts this behaviour for KeyEvent.KEYCODE_MEDIA_NEXT
and KeyEvent.KEYCODE_MEDIA_PREVIOUS
.
If everything works as intended (and the unit test above suggests this works), then you just have to override ForwardingPlayer.seekToNext()
and ForwardingPlayer.seekToPrevious()
where all the commands arrive and you can act accordingly.