1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2026-04-28 09:41:22 +00:00

-Added variable speed and pitch to background player.

-Moved playback speed LUT to BasePlayer.
This commit is contained in:
John Zhen M
2017-10-09 19:52:23 -07:00
committed by John Zhen Mo
parent 77979eddde
commit 94f7baf299
4 changed files with 122 additions and 10 deletions

View File

@@ -142,6 +142,9 @@ public abstract class BasePlayer implements Player.EventListener,
// Playback
//////////////////////////////////////////////////////////////////////////*/
protected static final float[] PLAYBACK_SPEEDS = {0.5f, 0.75f, 1f, 1.25f, 1.5f, 1.75f, 2f};
protected static final float[] PLAYBACK_PITCHES = {0.8f, 0.9f, 0.95f, 1f, 1.05f, 1.1f, 1.2f};
protected MediaSourceManager playbackManager;
protected PlayQueue playQueue;
@@ -862,6 +865,7 @@ public abstract class BasePlayer implements Player.EventListener,
private final StringBuilder stringBuilder = new StringBuilder();
private final Formatter formatter = new Formatter(stringBuilder, Locale.getDefault());
private final NumberFormat speedFormatter = new DecimalFormat("0.##x");
private final NumberFormat pitchFormatter = new DecimalFormat("##.##%");
// todo: merge this into Localization
public String getTimeString(int milliSeconds) {
@@ -880,6 +884,10 @@ public abstract class BasePlayer implements Player.EventListener,
return speedFormatter.format(speed);
}
protected String formatPitch(float pitch) {
return pitchFormatter.format(pitch);
}
protected void startProgressLoop() {
if (progressUpdateReactor != null) progressUpdateReactor.dispose();
progressUpdateReactor = getProgressReactor();
@@ -990,11 +998,28 @@ public abstract class BasePlayer implements Player.EventListener,
}
public float getPlaybackSpeed() {
return simpleExoPlayer.getPlaybackParameters().speed;
return getPlaybackParameters().speed;
}
public float getPlaybackPitch() {
return getPlaybackParameters().pitch;
}
public void setPlaybackSpeed(float speed) {
simpleExoPlayer.setPlaybackParameters(new PlaybackParameters(speed, 1f));
setPlaybackParameters(speed, getPlaybackPitch());
}
public void setPlaybackPitch(float pitch) {
setPlaybackParameters(getPlaybackSpeed(), pitch);
}
public PlaybackParameters getPlaybackParameters() {
final PlaybackParameters parameters = simpleExoPlayer.getPlaybackParameters();
return parameters == null ? new PlaybackParameters(1f, 1f) : parameters;
}
public void setPlaybackParameters(float speed, float pitch) {
simpleExoPlayer.setPlaybackParameters(new PlaybackParameters(speed, pitch));
}
public int getCurrentQueueIndex() {