Skip to content
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

How can I remove player commands of the platform mediasession? #542

Open
darrentaft opened this issue Jul 25, 2023 · 8 comments
Open

How can I remove player commands of the platform mediasession? #542

darrentaft opened this issue Jul 25, 2023 · 8 comments
Assignees

Comments

@darrentaft
Copy link

We offer live DASH streams within our app. We're using our own custom player controls, so have full control over what the user can do - i.e. when it's on-demand content we allow them to seek/pause/skip/etc, but when it's live they can only stop the stream.

With the standard integration of Media3 into MediaSession, we're finding that the Picture-In-Picture window is automatically offering player controls. This is great for on-demand content, but for our live streams we don't want the user being able to pause or seek the stream (as there's only a 44 second seekable window).

I can see a "setAvailableCommands" option on the MediaSession, however I can't work out where to get the additional "controller" and "sessionCommands" parameters from. I tried using the listener onConnect() approach, but it had no effect.

Google hasn't helped me find any suitable answers - either for Media3, or for ExoPlayer.

@oceanjules
Copy link
Contributor

How about:

/** Returns the list of connected controllers. */
public final List<ControllerInfo> getConnectedControllers() {
return impl.getConnectedControllers();
}

@tonihei
Copy link
Collaborator

tonihei commented Jul 26, 2023

I tried using the listener onConnect() approach, but it had no effect.

Ideally, the case you described should be handled in this method. @marcbaechinger Am I right in assuming that this is the problem you are currently addressing by moving the channeling the legacy controller through our internal Media3 controller? If so, we can use this issue to track this enhancement (or duplicate it if there already is one).

@darrentaft: As a workaround, you can wrap you player in a ForwardingPlayer when giving it to the MediaSession.Builder. And then override getAvailableCommands and isCommandAvailable to filter the available commands from your player.

@tonihei tonihei assigned tonihei and marcbaechinger and unassigned tonihei Jul 26, 2023
@marcbaechinger marcbaechinger changed the title How can I remove trickplay commands from a live stream mediasession? How can I remove player commands of the platform mediasession? Jul 26, 2023
@marcbaechinger
Copy link
Contributor

I'm not super-familiar with PiP, but I assume that Picture-in-Picture is connected to the platform session.

But yes, using a ForwardingPlayer as @tonihei suggested is the solution for now. There will be another approach for this soon that allows to set the available commands through a controller which then only affects the available player commands of the platform session. The ForwardingPlayer approach has the disadvantage that other Media3 controllers see the same restricted available player commands.

but for our live streams we don't want the user being able to pause or seek the stream

The mentioned approach would then also handle this for the notification for which I assume, the controls should be hidden for live in the same way.

I'll mark this issue as an enhancement to track the change we are talking about.

@darrentaft
Copy link
Author

That's great, thanks - I can confirm that ForwardingPlayer removes the play/pause button (although bizarrely it only disables the skip back/forward buttons, rather than removing them). That's good enough for now though.

@marcbaechinger
Copy link
Contributor

I think the button being disabled only may be the problem we have for Auto as well and is described in #339
The UI reflects the platform media session with a queue of a single item. Instead we need to provide a way to have the queue empty. I guess/believe then the next/prev buttons wouldn't show up.

@iamfaizzy
Copy link

iamfaizzy commented Nov 20, 2024

@darrentaft @marcbaechinger I attempted to achieve custom controls in Picture-in-Picture (PiP) mode using Media3Session, but it only allows disabling the "Next" and "Previous" controls rather than fully hiding them.

To work around this, I tried implementing a forwarding player, but the issue persisted. I also explored overriding the controls via onConnect() and setCustomLayout() to display a custom layout with "Play/Pause" and "10-second forward/backward" buttons. However, the default "Play/Pause," "Next," and "Previous" controls continue to appear. While it’s possible to disable "Next" and "Previous," there doesn’t seem to be a way to hide them entirely.

It seems the current implementation doesn’t fully support replacing the default controls in PiP mode. Could this limitation be addressed, or is there an alternative approach to completely customize the PiP controls? using mediaSession?

@marcbaechinger
Copy link
Contributor

Thanks for your comment.

It seems the current implementation doesn’t fully support replacing the default controls in PiP mode.

Can you let us know how you did this with the legacy MediaSessionCompat? I'm happy to research this some further but without knowing that and how this worked with the legacy session we should first clarify whether this is actually possible. So I've you have experience with that, please let us know.

@iamfaizzy
Copy link

On sample provided by google of mediaSessionCompat was also not able to hide only disabled and also not able to show other controls like increment/decrement ones instead of next and previous

In both cases play/pause is able to hide but not next and previous
Nor able to customise to show other controls instead of these.

This checked with PiP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants