Open BejanCorneliu opened 2 weeks ago
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.
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 :
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 ) :
Example 2 : If i add COMMAND_SEEK_TO_NEXT and COMMAND_SEEK_TO_PREVIOUS :
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
adb bugreport
to android-media-github@google.com after filing this issue.