-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Listen to MediaSession callbacks when using MediaSessionConnector #6446
Comments
@marcbaechinger, mind having a look? |
When you are using the PlayerView, PlayerNotificationManager and MediaSessionConnector there are three ways a user can issue player commands: PlayerControlView: You said you solved this already. Probably by using PlayerNotificationManager: has the same setControlDispatcher(controlDispatcher) method. You can use probably even use the same instance if you don't care from where the events are coming. MediaSessionConnector: has the same setControlDispatcher(controlDispatcher) method. You can use probably even use the same instance if you don't care from where the events are coming. In the case of the media session connector you need to make sure that all actions are enabled. By default this should be the following: PlaybackStateCompat.ACTION_PLAY_PAUSE |
Thanks, |
Just to follow-up on this - why is listening to player events not sufficient in this case? The player events are either user triggered or player triggered and you can tell by the type of event where it's coming from. So, for example, if you want to listen to user-triggered play/pause events, just listen to onPlayerStateChanged and check the playWhenReady value. |
In my original question i showed code that do exactly that. But using that i got |
You shouldn't check the playbackState (=state set by the player), just playWhenReady( =play/pause intention by the user):
|
That works too. Using |
Yes, I agree it's more direct. Just requires more work if you have multiple ways of interacting with the player (e.g. MediaSession + normal in-app-UI). And the callback would happen for all cases. And we are thinking of getting rid of the |
Closing again - question has been answered twice now :) |
We are interacting by MediaSession for normal in-app-UI, so it's single |
[REQUIRED] Searched documentation and issues
I searched information online and poked around
MediaSessionConnector
code.My issue is similar to #6057, but it's solution doesn't really work for me (explanation for that is in question itself).
[REQUIRED] Question
I need to report to FirebaseAnalytics events such as Play, Pause, Next and Previous (explicit user actions, not underlying changes in player state). When talking about UI - no problem here. But i stuck on trying to handle these events from
PlayerNotificationManager
orMediaSession
for that matter.The first idea was to use
MediaSession
callback. That would be the easiest way to do that. ButMediaSession
can have only one callback, andMediaSessionConnector
requires it. When usingPlayerNotificationManager
it provides me with play/pause/next/previous buttons, but i can't seem to get onClick callback for them.I managed to solve Next/Previous issue by reporting it from
QueueNavigator
using methodsonSkipToNext
andonSkipToPrevious
. But i can't find a reliable way to handle play/pause the same way. I tried this code:But i can't rely on it, since this callback represents change in player state and not explicit user action (i need to report user clicking on play button, not the player state itself). So when clicking Next button i got 2 events - next and then play (i need only next).
Is there any way around that? I mean - without handling
MediaSession
all by myself?The text was updated successfully, but these errors were encountered: