Skip to content

Support onSetPlaybackSpeed(speed, pitch) in MediaSessionConnector.ComponentListener  #8229

@mhelder

Description

@mhelder

Use case description

Android API 29 MediaController added setPlaybackSpeed(float), which was backported in MediaControllerCompat with androidx.media:media:1.2.0-alpha01. 1.2.0 become stable mid-September.

On the receiving end, MediaSessionCompat.Callback also added onSetPlaybackSpeed(float speed). Interestingly, the docs do not yet show this method, but it's definitely there for media:1.2.0. It's easy to miss anyways, because the Callback is an abstract class with empty methods, so nothing it forcing extending classes to actually implement this functionality. The same goes for ExoPlayer's MediaSessionConnector, which has a ComponentListener that extends MediaSessionCompat.Callback, but does not yet override onSetPlaybackSpeed(float speed).

TLDR: support for setting the playback speed is currently missing in ComponentListener.

Proposed solution

Override MediaSessionCompat.Callback.onSetPlaybackSpeed(float speed) in ComponentListener and forward the playback speed to the actual Player instance. In its most simple form, this could look somewhat like this:

@Override
public void onSetPlaybackSpeed(float speed) {
  float playbackPitch = player.getPlaybackParameters().pitch;
  player.setPlaybackParameters(new PlaybackParameters(speed, playbackPitch));
}

Alternatives considered

I wasn't sure whether to file this as bug or feature request, but settles on the latter, because as long as the mediasession extension is not targeting media:1.2.0, this is working as expected.

If you accept PRs for this matter, I'd be happy to submit one addressing the missing functionality. Although I'm not quite sure if there are any other features from media:1.1.0 or 1.2.0 that would need to be picked up at the same time?

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions