From d0e626c6eec8e499d367f2d66d4e76bc61815b7e Mon Sep 17 00:00:00 2001 From: John Zhen Mo Date: Sun, 22 Oct 2017 19:21:19 -0700 Subject: [PATCH] -Fixed popup and main video players not using different quality resolution. --- .../org/schabi/newpipe/player/MainVideoPlayer.java | 13 +++++++++++++ .../org/schabi/newpipe/player/PopupVideoPlayer.java | 9 ++++++++- .../java/org/schabi/newpipe/player/VideoPlayer.java | 6 ++++-- .../org/schabi/newpipe/util/NavigationHelper.java | 13 ------------- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java index e180c6d0d..e424e57b5 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java @@ -47,14 +47,18 @@ import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; import org.schabi.newpipe.R; import org.schabi.newpipe.extractor.stream.StreamInfo; +import org.schabi.newpipe.extractor.stream.VideoStream; import org.schabi.newpipe.playlist.PlayQueueItem; import org.schabi.newpipe.playlist.PlayQueueItemBuilder; import org.schabi.newpipe.playlist.PlayQueueItemHolder; import org.schabi.newpipe.util.AnimationUtils; +import org.schabi.newpipe.util.ListHelper; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.PermissionHelper; import org.schabi.newpipe.util.ThemeHelper; +import java.util.List; + import static org.schabi.newpipe.util.AnimationUtils.animateView; /** @@ -316,6 +320,10 @@ public final class MainVideoPlayer extends Activity { updatePlaybackButtons(); } + /*////////////////////////////////////////////////////////////////////////// + // Player Overrides + //////////////////////////////////////////////////////////////////////////*/ + @Override public void onFullScreenButtonClicked() { super.onFullScreenButtonClicked(); @@ -434,6 +442,11 @@ public final class MainVideoPlayer extends Activity { shutdown(); } + @Override + protected int getDefaultResolutionIndex(final List sortedVideos) { + return ListHelper.getDefaultResolutionIndex(context, sortedVideos); + } + /*////////////////////////////////////////////////////////////////////////// // States //////////////////////////////////////////////////////////////////////////*/ diff --git a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java index fad03adba..0983da4ef 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java @@ -64,6 +64,7 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamExtractor; import org.schabi.newpipe.extractor.stream.StreamInfo; +import org.schabi.newpipe.extractor.stream.VideoStream; import org.schabi.newpipe.player.event.PlayerEventListener; import org.schabi.newpipe.player.old.PlayVideoActivity; import org.schabi.newpipe.playlist.PlayQueueItem; @@ -72,11 +73,12 @@ import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.Constants; import org.schabi.newpipe.util.ExtractorHelper; -import org.schabi.newpipe.util.Localization; +import org.schabi.newpipe.util.ListHelper; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.ThemeHelper; import java.io.IOException; +import java.util.List; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; @@ -496,6 +498,11 @@ public final class PopupVideoPlayer extends Service { updateProgress(currentProgress, duration, bufferPercent); } + @Override + protected int getDefaultResolutionIndex(final List sortedVideos) { + return ListHelper.getPopupDefaultResolutionIndex(context, sortedVideos); + } + /*////////////////////////////////////////////////////////////////////////// // Activity Event Listener //////////////////////////////////////////////////////////////////////////*/ diff --git a/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java index 196be8229..84a2519f7 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java @@ -230,6 +230,8 @@ public abstract class VideoPlayer extends BasePlayer implements SimpleExoPlayer. // Playback Listener //////////////////////////////////////////////////////////////////////////*/ + protected abstract int getDefaultResolutionIndex(final List sortedVideos); + @Override public void sync(@NonNull final PlayQueueItem item, @Nullable final StreamInfo info) { super.sync(item, info); @@ -241,7 +243,7 @@ public abstract class VideoPlayer extends BasePlayer implements SimpleExoPlayer. availableStreams = new ArrayList<>(videos); final int qualityIndex = item.getQualityIndex(); if (qualityIndex == PlayQueueItem.DEFAULT_QUALITY) { - selectedStreamIndex = ListHelper.getDefaultResolutionIndex(context, videos); + selectedStreamIndex = getDefaultResolutionIndex(videos); } else { selectedStreamIndex = qualityIndex; } @@ -260,7 +262,7 @@ public abstract class VideoPlayer extends BasePlayer implements SimpleExoPlayer. final VideoStream video; if (sortedStreamsIndex == PlayQueueItem.DEFAULT_QUALITY) { - final int index = ListHelper.getDefaultResolutionIndex(context, videos); + final int index = getDefaultResolutionIndex(videos); video = videos.get(index); } else { video = videos.get(sortedStreamsIndex); diff --git a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java index 9df9b3055..6cbefaf0f 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -6,7 +6,6 @@ import android.content.Intent; import android.preference.PreferenceManager; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; -import android.text.TextUtils; import com.nostra13.universalimageloader.core.ImageLoader; @@ -14,14 +13,10 @@ import org.schabi.newpipe.MainActivity; import org.schabi.newpipe.R; import org.schabi.newpipe.about.AboutActivity; import org.schabi.newpipe.download.DownloadActivity; -import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.ServiceList; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ExtractionException; -import org.schabi.newpipe.extractor.playlist.PlaylistInfo; -import org.schabi.newpipe.extractor.stream.AudioStream; -import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.fragments.MainFragment; import org.schabi.newpipe.fragments.detail.VideoDetailFragment; import org.schabi.newpipe.fragments.list.channel.ChannelFragment; @@ -30,19 +25,11 @@ import org.schabi.newpipe.fragments.list.kiosk.KioskFragment; import org.schabi.newpipe.fragments.list.playlist.PlaylistFragment; import org.schabi.newpipe.fragments.list.search.SearchFragment; import org.schabi.newpipe.history.HistoryActivity; -import org.schabi.newpipe.player.BackgroundPlayer; import org.schabi.newpipe.player.BasePlayer; import org.schabi.newpipe.player.VideoPlayer; -import org.schabi.newpipe.playlist.ExternalPlayQueue; import org.schabi.newpipe.playlist.PlayQueue; -import org.schabi.newpipe.playlist.SinglePlayQueue; import org.schabi.newpipe.settings.SettingsActivity; -import java.util.ArrayList; -import java.util.List; - -import static android.text.TextUtils.split; - @SuppressWarnings({"unused", "WeakerAccess"}) public class NavigationHelper { public static final String MAIN_FRAGMENT_TAG = "main_fragment_tag";