Change playback speed in Exoplayer

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

+8
source share
4 answers

The setPlaybackSpeed() function setPlaybackSpeed() been removed, and now you set the playback speed with:

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

speed is a floating point number. Normal speed is 1f and double speed is 2f .

+13
source

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 the processOutputBuffer method and process it through Sonic.java before sending it to AudioTrack .

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

+3
source

Try it

I followed all the answers, nothing worked, so I tried the solution below, it works for me

 PlaybackParams param = new PlaybackParams(); param.setSpeed(1f);// 1f is 1x, 2f is 2x exoPlayer.setPlaybackParams(param); 
0
source

You should look at this project, which was very useful for me: https://github.com/AmrMohammed89/exoplayer2.4.0_speedup

Inside SimpleExoPlayer, I applied the following methods:

  private final ExoPlayer player; private float playbackSpeed; float SPEED_NORMAL = 1f; float SPEED_MEDIUM = 1.5f; float SPEED_HIGH = 2f; @Override public float getPlaybackSpeed() { return playbackSpeed; } @Override public void setPlaybackSpeed(float speed) { playbackSpeed = speed; player.setPlaybackSpeed(speed); } @Override public void changePlaybackSpeed() { if (playbackSpeed == SPEED_MEDIUM) { player.setPlaybackSpeed(SPEED_HIGH); playbackSpeed = SPEED_HIGH; } else if (playbackSpeed == SPEED_HIGH) { player.setPlaybackSpeed(SPEED_NORMAL); playbackSpeed = SPEED_NORMAL; } else { player.setPlaybackSpeed(SPEED_MEDIUM); playbackSpeed = SPEED_MEDIUM; } } 

I set and saved the speed this way due to an error when I tried to get the last saved speed. So, follow this mechanism and it will work perfectly.

Greetings

-1
source

Source: https://habr.com/ru/post/1234584/


All Articles