added playback parameters dialog to local player
can be accessed by long-touching the player
This commit is contained in:
parent
685491a674
commit
a1f4f776b7
2 changed files with 50 additions and 3 deletions
|
@ -13,6 +13,7 @@ import android.view.WindowManager;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.google.android.exoplayer2.PlaybackParameters;
|
||||
import com.google.android.exoplayer2.Player;
|
||||
import com.google.android.exoplayer2.SimpleExoPlayer;
|
||||
import com.google.android.exoplayer2.ui.PlayerView;
|
||||
|
@ -21,13 +22,15 @@ import com.grack.nanojson.JsonParser;
|
|||
|
||||
import org.schabi.newpipe.player.LocalPlayer;
|
||||
import org.schabi.newpipe.player.LocalPlayerListener;
|
||||
import org.schabi.newpipe.player.helper.PlaybackParameterDialog;
|
||||
import org.schabi.newpipe.util.ThemeHelper;
|
||||
import org.schabi.newpipe.util.VideoSegment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LocalPlayerActivity extends AppCompatActivity implements Player.EventListener,
|
||||
LocalPlayerListener {
|
||||
LocalPlayerListener, PlaybackParameterDialog.Callback {
|
||||
private LocalPlayer localPlayer;
|
||||
public static final String TAG = "LocalPlayerActivity";
|
||||
|
||||
|
@ -35,6 +38,7 @@ public class LocalPlayerActivity extends AppCompatActivity implements Player.Eve
|
|||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_local_player);
|
||||
ThemeHelper.setTheme(this);
|
||||
|
||||
hideSystemUi(isLandscape());
|
||||
|
||||
|
@ -48,6 +52,19 @@ public class LocalPlayerActivity extends AppCompatActivity implements Player.Eve
|
|||
|
||||
final PlayerView playerView = findViewById(R.id.player_view);
|
||||
playerView.setPlayer(localPlayer.getExoPlayer());
|
||||
|
||||
playerView.getVideoSurfaceView().setOnLongClickListener(v -> {
|
||||
showPlaybackParameterDialog();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public void showPlaybackParameterDialog() {
|
||||
final PlaybackParameters playbackParameters =
|
||||
localPlayer.getExoPlayer().getPlaybackParameters();
|
||||
PlaybackParameterDialog.newInstance(playbackParameters.speed, playbackParameters.pitch,
|
||||
playbackParameters.skipSilence, this)
|
||||
.show(getSupportFragmentManager(), TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,6 +80,12 @@ public class LocalPlayerActivity extends AppCompatActivity implements Player.Eve
|
|||
hideSystemUi(isLandscape());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaybackParameterChanged(final float playbackTempo, final float playbackPitch,
|
||||
final boolean playbackSkipSilence) {
|
||||
localPlayer.setPlaybackParameters(playbackTempo, playbackPitch, playbackSkipSilence);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlocked(final SimpleExoPlayer player) {
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.widget.Toast;
|
|||
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.google.android.exoplayer2.PlaybackParameters;
|
||||
import com.google.android.exoplayer2.Player.EventListener;
|
||||
import com.google.android.exoplayer2.SeekParameters;
|
||||
import com.google.android.exoplayer2.SimpleExoPlayer;
|
||||
|
@ -15,7 +16,6 @@ import com.google.android.exoplayer2.source.MediaSource;
|
|||
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
|
||||
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
||||
|
||||
import org.schabi.newpipe.App;
|
||||
import org.schabi.newpipe.DownloaderImpl;
|
||||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.player.helper.PlayerHelper;
|
||||
|
@ -48,7 +48,7 @@ public class LocalPlayer implements EventListener {
|
|||
|
||||
public LocalPlayer(final Context context) {
|
||||
this.context = context;
|
||||
this.mPrefs = PreferenceManager.getDefaultSharedPreferences(App.getApp());
|
||||
this.mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
}
|
||||
|
||||
public void initialize(final String uri, final VideoSegment[] segments) {
|
||||
|
@ -62,6 +62,16 @@ public class LocalPlayer implements EventListener {
|
|||
simpleExoPlayer.setSeekParameters(PlayerHelper.getSeekParameters(context));
|
||||
simpleExoPlayer.setHandleAudioBecomingNoisy(true);
|
||||
|
||||
final PlaybackParameters playbackParameters = simpleExoPlayer.getPlaybackParameters();
|
||||
final float speed = mPrefs.getFloat(context.getString(
|
||||
R.string.playback_speed_key), playbackParameters.speed);
|
||||
final float pitch = mPrefs.getFloat(context.getString(
|
||||
R.string.playback_pitch_key), playbackParameters.pitch);
|
||||
final boolean skipSilence = mPrefs.getBoolean(context.getString(
|
||||
R.string.playback_skip_silence_key), playbackParameters.skipSilence);
|
||||
|
||||
setPlaybackParameters(speed, pitch, skipSilence);
|
||||
|
||||
final String autoPlayStr =
|
||||
mPrefs.getString(context.getString(R.string.autoplay_key), "");
|
||||
final boolean autoPlay =
|
||||
|
@ -94,6 +104,20 @@ public class LocalPlayer implements EventListener {
|
|||
progressUpdateReactor.set(null);
|
||||
}
|
||||
|
||||
public void setPlaybackParameters(final float speed, final float pitch,
|
||||
final boolean skipSilence) {
|
||||
final float roundedSpeed = Math.round(speed * 100.0f) / 100.0f;
|
||||
final float roundedPitch = Math.round(pitch * 100.0f) / 100.0f;
|
||||
|
||||
mPrefs.edit()
|
||||
.putFloat(context.getString(R.string.playback_speed_key), speed)
|
||||
.putFloat(context.getString(R.string.playback_pitch_key), pitch)
|
||||
.putBoolean(context.getString(R.string.playback_skip_silence_key), skipSilence)
|
||||
.apply();
|
||||
simpleExoPlayer.setPlaybackParameters(
|
||||
new PlaybackParameters(roundedSpeed, roundedPitch, skipSilence));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerStateChanged(final boolean playWhenReady, final int playbackState) {
|
||||
switch (playbackState) {
|
||||
|
|
Loading…
Reference in a new issue