Controlling the speed in ExoPlayer via MediaBrowserServiceCompat

162 Views Asked by At

How can I control the speed from an exo player via the UI to MediaBrowserServiceCompat?

Does Android provide a normal solution for it?

1

There are 1 best solutions below

0
On

In the end, I did it like this.

In the activity I did this:

MediaControllerCompat.getMediaController(ChatActivity.this).sendCommand("speed",bundle,new ResultReceiver(new Handler(Looper.getMainLooper()))

And in the MediaBrowserServiceCompat I did it like this:

private MediaSessionConnector.QueueEditor getQueueEditor() {
    return new MediaSessionConnector.QueueEditor() {
        @Override
        public boolean onCommand(Player player, String command, @Nullable Bundle extras, @Nullable ResultReceiver cb) {
            float speed = extras.getFloat("SpeedProgress");
            PlaybackParameters param = new PlaybackParameters(speed);
            player.setPlaybackParameters(param);
            player.setPlaybackSpeed(speed);
            return false;
        }