Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing playback speed in Exoplayer

I'm looking to implement an audio player with variable speed playback (1.0x, 1.25x, 1.5x) like typical audiobook players currently on the market do. I would like to use Google's Exoplayer library as my audioplayer library however they don't appear to support variable speed playback. Any ideas on how to implement this, or any extensions that do support this?

like image 257
two1stnamz Avatar asked Aug 11 '15 16:08

two1stnamz


People also ask

How do I change playback speed in ExoPlayer?

To change the playback speed, call ExoPlayer. setPlaybackParameters passing in a PlaybackParameters instance with the required speed. As noted in the method's Javadoc, setting the playback parameters is not always possible.

How do I change playback speed in ExoPlayer Android?

The function setPlaybackSpeed() was removed and now you set the playback speed via: PlaybackParameters param = new PlaybackParameters(speed); mExoPlayer. setPlaybackParameters(param); speed is a float number.

How do I get ExoPlayer thumbnails on Android?

As per the Exo player developer console, it's mentioned that Exo player only used for the Audio and Video. Add ImageView and Exoplayer in Framelayout. Show Image (That is knows as thumbnails) in imageView and on tap of ImageView Hide it and show ExoPlayer and play it.


4 Answers

The function setPlaybackSpeed() was removed and now you set the playback speed via:

    PlaybackParameters param = new PlaybackParameters(speed);
    mExoPlayer.setPlaybackParameters(param);

speed is a float number. Normal speed is 1f and double the speed would be 2f.

like image 67
Christian Avatar answered Sep 22 '22 17:09

Christian


Kotlin Extension Solution

Make it easy to access and set this reliably across your app in Kotlin

// To set
player.playbackSpeed = 2f

var SimpleExoPlayer.playbackSpeed: Float
    get() = playbackParameters?.speed ?: 1f
    set(speed) {
        val pitch = playbackParameters?.pitch ?: 1f
        playbackParameters = PlaybackParameters(speed, pitch)
    }
like image 23
Gibolt Avatar answered Sep 21 '22 17:09

Gibolt


All you need is https://github.com/waywardgeek/sonic/blob/master/Sonic.java

If you look at MediaCodecAudioTrackRenderer.java, you can get the output buffer (decoded by MediaCodec) from ExoPlayer in method processOutputBuffer and process it through Sonic.java accordingly before sending it to AudioTrack.

Following document explains how to use libsonic https://github.com/waywardgeek/sonic/blob/master/doc/index.md

like image 26
T.J Avatar answered Sep 21 '22 17:09

T.J


Try This

I have followed all the answer nothing worked, so i have tried the below solution, it works for me

PlaybackParams param = new PlaybackParams();
param.setSpeed(1f);// 1f is 1x, 2f is 2x 
exoPlayer.setPlaybackParams(param);
like image 3
Sunil Avatar answered Sep 21 '22 17:09

Sunil