From 685491a674e91e102d0f8b7e12034b6d6dd01305 Mon Sep 17 00:00:00 2001 From: polymorphicshade Date: Tue, 23 Feb 2021 18:20:55 -0700 Subject: [PATCH] made the local player respect the auto play setting ...also some minor refactoring --- .../org/schabi/newpipe/LocalPlayerActivity.java | 14 +++++++++----- .../org/schabi/newpipe/player/LocalPlayer.java | 11 +++++++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/LocalPlayerActivity.java b/app/src/main/java/org/schabi/newpipe/LocalPlayerActivity.java index f38f2bb7a..725d34534 100644 --- a/app/src/main/java/org/schabi/newpipe/LocalPlayerActivity.java +++ b/app/src/main/java/org/schabi/newpipe/LocalPlayerActivity.java @@ -40,14 +40,14 @@ public class LocalPlayerActivity extends AppCompatActivity implements Player.Eve final Intent intent = getIntent(); - final String uri = intent.getDataString(); - final VideoSegment[] segments = getSegmentsFromIntent(intent); + final String uri = parseUriFromIntent(intent); + final VideoSegment[] segments = parseSegmentsFromIntent(intent); localPlayer = new LocalPlayer(this); - localPlayer.initPlayer(uri, segments); + localPlayer.initialize(uri, segments); final PlayerView playerView = findViewById(R.id.player_view); - playerView.setPlayer(localPlayer.getPlayer()); + playerView.setPlayer(localPlayer.getExoPlayer()); } @Override @@ -93,7 +93,11 @@ public class LocalPlayerActivity extends AppCompatActivity implements Player.Eve setKeepScreenOn(false); } - private static VideoSegment[] getSegmentsFromIntent(final Intent intent) { + private static String parseUriFromIntent(final Intent intent) { + return intent.getDataString(); + } + + private static VideoSegment[] parseSegmentsFromIntent(final Intent intent) { final List result = new ArrayList<>(); final String segmentsJson = intent.getStringExtra("segments"); diff --git a/app/src/main/java/org/schabi/newpipe/player/LocalPlayer.java b/app/src/main/java/org/schabi/newpipe/player/LocalPlayer.java index aa5397a11..54719f3e1 100644 --- a/app/src/main/java/org/schabi/newpipe/player/LocalPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/LocalPlayer.java @@ -51,7 +51,7 @@ public class LocalPlayer implements EventListener { this.mPrefs = PreferenceManager.getDefaultSharedPreferences(App.getApp()); } - public void initPlayer(final String uri, final VideoSegment[] segments) { + public void initialize(final String uri, final VideoSegment[] segments) { this.videoSegments = segments; this.progressUpdateReactor = new SerialDisposable(); @@ -62,6 +62,13 @@ public class LocalPlayer implements EventListener { simpleExoPlayer.setSeekParameters(PlayerHelper.getSeekParameters(context)); simpleExoPlayer.setHandleAudioBecomingNoisy(true); + final String autoPlayStr = + mPrefs.getString(context.getString(R.string.autoplay_key), ""); + final boolean autoPlay = + !autoPlayStr.equals(context.getString(R.string.autoplay_never_key)); + + simpleExoPlayer.setPlayWhenReady(autoPlay); + if (uri == null || uri.length() == 0) { return; } @@ -72,7 +79,7 @@ public class LocalPlayer implements EventListener { simpleExoPlayer.prepare(videoSource); } - public SimpleExoPlayer getPlayer() { + public SimpleExoPlayer getExoPlayer() { return this.simpleExoPlayer; }