Speed up audio on double tap

This commit is contained in:
Niels Andriesse 2021-06-28 15:49:29 +10:00
parent f44e655361
commit fa71c81ea9
2 changed files with 13 additions and 1 deletions

View File

@ -23,6 +23,7 @@ import com.google.android.exoplayer2.DefaultRenderersFactory;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.LoadControl;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.audio.AudioAttributes;
@ -284,6 +285,16 @@ public class AudioSlidePlayer implements SensorEventListener {
}
}
public float getPlaybackSpeed() {
if (mediaPlayer == null) { return 1.0f; }
return mediaPlayer.getPlaybackParameters().speed;
}
public void setPlaybackSpeed(float speed) {
if (mediaPlayer == null) { return; }
mediaPlayer.setPlaybackParameters(new PlaybackParameters(speed));
}
private void notifyOnStart() {
Util.runOnMain(() -> getListener().onPlayerStart(AudioSlidePlayer.this));
}

View File

@ -105,7 +105,8 @@ class VoiceMessageView : LinearLayout, AudioSlidePlayer.Listener {
}
fun handleDoubleTap() {
Log.d("Test", "handleDoubleTap()")
val player = this.player ?: return
player.playbackSpeed = if (player.playbackSpeed == 1.0f) 1.5f else 1.0f
}
// endregion
}