From 2a2c82e73bb2380c07ab848b185952ab183a5502 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sat, 31 Oct 2020 20:26:09 +0100 Subject: [PATCH] More fixes with opening VideoDetailFragment --- .../org/schabi/newpipe/RouterActivity.java | 2 +- .../fragments/detail/VideoDetailFragment.java | 4 +- .../player/BackgroundPlayerActivity.java | 28 --------- .../org/schabi/newpipe/player/BasePlayer.java | 33 ++++++----- .../org/schabi/newpipe/player/MainPlayer.java | 2 +- .../newpipe/player/ServicePlayerActivity.java | 47 ++++++--------- .../newpipe/player/VideoPlayerImpl.java | 48 +++------------ .../player/event/BasePlayerGestureListener.kt | 5 +- .../newpipe/player/helper/AudioReactor.java | 2 +- .../newpipe/player/helper/PlayerHelper.java | 6 +- .../newpipe/player/helper/PlayerHolder.java | 7 +++ .../player/playqueue/PlayQueueItem.java | 14 +++++ .../schabi/newpipe/util/NavigationHelper.java | 59 ++++--------------- 13 files changed, 87 insertions(+), 170 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/RouterActivity.java b/app/src/main/java/org/schabi/newpipe/RouterActivity.java index 4f563a1d1c6..537d71901ec 100644 --- a/app/src/main/java/org/schabi/newpipe/RouterActivity.java +++ b/app/src/main/java/org/schabi/newpipe/RouterActivity.java @@ -685,7 +685,7 @@ public Consumer getResultHandler(final Choice choice) { } if (choice.playerChoice.equals(videoPlayerKey)) { - NavigationHelper.playOnMainPlayer(this, playQueue); + NavigationHelper.playOnMainPlayer(this, playQueue, false); } else if (choice.playerChoice.equals(backgroundPlayerKey)) { NavigationHelper.playOnBackgroundPlayer(this, playQueue, true); } else if (choice.playerChoice.equals(popupPlayerKey)) { diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index ffba7f5216b..1324d6832d7 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -1097,7 +1097,7 @@ private void openNormalBackgroundPlayer(final boolean append) { private void openMainPlayer() { if (playerService == null) { - PlayerHolder.startService(App.getApp(), true, this); + PlayerHolder.startService(App.getApp(), autoPlayEnabled, this); return; } if (currentInfo == null) { @@ -1112,7 +1112,7 @@ private void openMainPlayer() { addVideoPlayerView(); final Intent playerIntent = NavigationHelper - .getPlayerIntent(requireContext(), MainPlayer.class, queue, null, true); + .getPlayerIntent(requireContext(), MainPlayer.class, queue, true, autoPlayEnabled); activity.startService(playerIntent); } diff --git a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayerActivity.java b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayerActivity.java index 0e5222f5e5f..2fc710fb0b3 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayerActivity.java +++ b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayerActivity.java @@ -2,11 +2,8 @@ import android.content.Intent; import android.view.Menu; -import android.view.MenuItem; import org.schabi.newpipe.R; -import org.schabi.newpipe.util.NavigationHelper; -import org.schabi.newpipe.util.PermissionHelper; public final class BackgroundPlayerActivity extends ServicePlayerActivity { @@ -46,31 +43,6 @@ public int getPlayerOptionMenuResource() { return R.menu.menu_play_queue_bg; } - @Override - public boolean onPlayerOptionSelected(final MenuItem item) { - if (item.getItemId() == R.id.action_switch_popup) { - - if (!PermissionHelper.isPopupEnabled(this)) { - PermissionHelper.showPopupEnablementToast(this); - return true; - } - - this.player.setRecovery(); - NavigationHelper.playOnPopupPlayer( - getApplicationContext(), player.playQueue, this.player.isPlaying()); - return true; - } - - if (item.getItemId() == R.id.action_switch_background) { - this.player.setRecovery(); - NavigationHelper.playOnBackgroundPlayer( - getApplicationContext(), player.playQueue, this.player.isPlaying()); - return true; - } - - return false; - } - @Override public void setupMenu(final Menu menu) { if (player == null) { diff --git a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java index 70f2e158b9f..1355f428561 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -125,7 +125,7 @@ public abstract class BasePlayer implements @NonNull public static final String RESUME_PLAYBACK = "resume_playback"; @NonNull - public static final String START_PAUSED = "start_paused"; + public static final String PLAY_WHEN_READY = "play_when_ready"; @NonNull public static final String SELECT_ON_APPEND = "select_on_append"; @NonNull @@ -224,7 +224,7 @@ public void onReceive(final Context ctx, final Intent intent) { this.dataSource = new PlayerDataSource(context, userAgent, bandwidthMeter); final TrackSelection.Factory trackSelectionFactory = PlayerHelper - .getQualitySelector(context); + .getQualitySelector(); this.trackSelector = new CustomTrackSelector(context, trackSelectionFactory); this.loadControl = new LoadController(); @@ -302,6 +302,7 @@ public void handleIntent(final Intent intent) { final boolean samePlayQueue = playQueue != null && playQueue.equals(queue); final int repeatMode = intent.getIntExtra(REPEAT_MODE, getRepeatMode()); + final boolean playWhenReady = intent.getBooleanExtra(PLAY_WHEN_READY, true); final boolean isMuted = intent .getBooleanExtra(IS_MUTED, simpleExoPlayer != null && isMuted()); @@ -327,16 +328,20 @@ public void handleIntent(final Intent intent) { simpleExoPlayer.retry(); } simpleExoPlayer.seekTo(playQueue.getIndex(), queue.getItem().getRecoveryPosition()); - return; + simpleExoPlayer.setPlayWhenReady(playWhenReady); - } else if (samePlayQueue && !playQueue.isDisposed() && simpleExoPlayer != null) { + } else if (simpleExoPlayer != null + && samePlayQueue + && playQueue != null + && !playQueue.isDisposed()) { // Do not re-init the same PlayQueue. Save time // Player can have state = IDLE when playback is stopped or failed // and we should retry() in this case if (simpleExoPlayer.getPlaybackState() == Player.STATE_IDLE) { simpleExoPlayer.retry(); } - return; + simpleExoPlayer.setPlayWhenReady(playWhenReady); + } else if (intent.getBooleanExtra(RESUME_PLAYBACK, false) && isPlaybackResumeEnabled() && !samePlayQueue) { @@ -351,7 +356,7 @@ && isPlaybackResumeEnabled() state -> { queue.setRecovery(queue.getIndex(), state.getProgressTime()); initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, - playbackSkipSilence, true, isMuted); + playbackSkipSilence, playWhenReady, isMuted); }, error -> { if (DEBUG) { @@ -359,24 +364,22 @@ && isPlaybackResumeEnabled() } // In case any error we can start playback without history initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, - playbackSkipSilence, true, isMuted); + playbackSkipSilence, playWhenReady, isMuted); }, () -> { // Completed but not found in history initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, - playbackSkipSilence, true, isMuted); + playbackSkipSilence, playWhenReady, isMuted); } ); databaseUpdateReactor.add(stateLoader); - return; } + } else { + // Good to go... + // In a case of equal PlayQueues we can re-init old one but only when it is disposed + initPlayback(samePlayQueue ? playQueue : queue, repeatMode, playbackSpeed, + playbackPitch, playbackSkipSilence, playWhenReady, isMuted); } - // Good to go... - // In a case of equal PlayQueues we can re-init old one but only when it is disposed - initPlayback(samePlayQueue ? playQueue : queue, repeatMode, - playbackSpeed, playbackPitch, playbackSkipSilence, - !intent.getBooleanExtra(START_PAUSED, false), - isMuted); } private PlaybackParameters retrievePlaybackParametersFromPreferences() { diff --git a/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java b/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java index ea205bbdfe1..07ca7b33968 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java @@ -240,7 +240,7 @@ public View getView() { } public void removeViewFromParent() { - if (getView().getParent() != null) { + if (getView() != null && getView().getParent() != null) { if (playerImpl.getParentActivity() != null) { // This means view was added to fragment final ViewGroup parent = (ViewGroup) getView().getParent(); diff --git a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java index fee189295ea..ad4c603cdbc 100644 --- a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java +++ b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java @@ -27,9 +27,7 @@ import com.google.android.exoplayer2.PlaybackParameters; import com.google.android.exoplayer2.Player; -import org.schabi.newpipe.MainActivity; import org.schabi.newpipe.R; -import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.fragments.OnScrollBelowItemsListener; import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; @@ -42,9 +40,9 @@ import org.schabi.newpipe.player.playqueue.PlayQueueItemBuilder; import org.schabi.newpipe.player.playqueue.PlayQueueItemHolder; import org.schabi.newpipe.player.playqueue.PlayQueueItemTouchCallback; -import org.schabi.newpipe.util.Constants; import org.schabi.newpipe.util.Localization; import org.schabi.newpipe.util.NavigationHelper; +import org.schabi.newpipe.util.PermissionHelper; import org.schabi.newpipe.util.ThemeHelper; import java.util.Collections; @@ -113,9 +111,8 @@ public abstract class ServicePlayerActivity extends AppCompatActivity public abstract int getPlayerOptionMenuResource(); - public abstract boolean onPlayerOptionSelected(MenuItem item); - public abstract void setupMenu(Menu m); + //////////////////////////////////////////////////////////////////////////// // Activity Lifecycle //////////////////////////////////////////////////////////////////////////// @@ -187,12 +184,22 @@ public boolean onOptionsItemSelected(final MenuItem item) { return true; case R.id.action_switch_main: this.player.setRecovery(); - getApplicationContext().startActivity( - getSwitchIntent(MainActivity.class, MainPlayer.PlayerType.VIDEO) - .putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying())); + NavigationHelper.playOnMainPlayer(this, player.getPlayQueue(), true); + return true; + case R.id.action_switch_popup: + if (PermissionHelper.isPopupEnabled(this)) { + this.player.setRecovery(); + NavigationHelper.playOnPopupPlayer(this, player.playQueue, true); + } else { + PermissionHelper.showPopupEnablementToast(this); + } + return true; + case R.id.action_switch_background: + this.player.setRecovery(); + NavigationHelper.playOnBackgroundPlayer(this, player.playQueue, true); return true; } - return onPlayerOptionSelected(item) || super.onOptionsItemSelected(item); + return super.onOptionsItemSelected(item); } @Override @@ -201,24 +208,6 @@ protected void onDestroy() { unbind(); } - protected Intent getSwitchIntent(final Class clazz, final MainPlayer.PlayerType playerType) { - return NavigationHelper.getPlayerIntent(getApplicationContext(), clazz, - this.player.getPlayQueue(), this.player.getRepeatMode(), - this.player.getPlaybackSpeed(), this.player.getPlaybackPitch(), - this.player.getPlaybackSkipSilence(), - null, - true, - !this.player.isPlaying(), - this.player.isMuted()) - .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - .putExtra(Constants.KEY_LINK_TYPE, StreamingService.LinkType.STREAM) - .putExtra(Constants.KEY_URL, this.player.getVideoUrl()) - .putExtra(Constants.KEY_TITLE, this.player.getVideoTitle()) - .putExtra(Constants.KEY_SERVICE_ID, - this.player.getCurrentMetadata().getMetadata().getServiceId()) - .putExtra(VideoPlayer.PLAYER_TYPE, playerType); - } - //////////////////////////////////////////////////////////////////////////// // Service Connection //////////////////////////////////////////////////////////////////////////// @@ -368,8 +357,8 @@ private void buildItemPopupMenu(final PlayQueueItem item, final View view) { Menu.NONE, R.string.play_queue_stream_detail); detail.setOnMenuItemClickListener(menuItem -> { // playQueue is null since we don't want any queue change - NavigationHelper.openVideoDetail( - this, item.getServiceId(), item.getUrl(), item.getTitle(), null); + NavigationHelper.openVideoDetail(this, item.getServiceId(), item.getUrl(), + item.getTitle(), null, false); return true; }); diff --git a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java index 765eb148beb..fa016e15895 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java @@ -76,9 +76,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.nostra13.universalimageloader.core.assist.FailReason; -import org.schabi.newpipe.MainActivity; import org.schabi.newpipe.R; -import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.extractor.stream.VideoStream; import org.schabi.newpipe.fragments.OnScrollBelowItemsListener; @@ -97,7 +95,6 @@ import org.schabi.newpipe.player.resolver.MediaSourceTag; import org.schabi.newpipe.player.resolver.VideoPlaybackResolver; import org.schabi.newpipe.util.AnimationUtils; -import org.schabi.newpipe.util.Constants; import org.schabi.newpipe.util.DeviceUtils; import org.schabi.newpipe.util.KoreUtil; import org.schabi.newpipe.util.ListHelper; @@ -260,7 +257,12 @@ public void handleIntent(final Intent intent) { onQueueClosed(); // Android TV: without it focus will frame the whole player playPauseButton.requestFocus(); - onPlay(); + + if (simpleExoPlayer.getPlayWhenReady()) { + onPlay(); + } else { + onPause(); + } } NavigationHelper.sendPlayerStartedEvent(service); } @@ -756,40 +758,6 @@ public void toggleFullscreen() { setupScreenRotationButton(); } - public void switchFromPopupToMain() { - if (DEBUG) { - Log.d(TAG, "switchFromPopupToMain() called"); - } - if (!popupPlayerSelected() || simpleExoPlayer == null || getCurrentMetadata() == null) { - return; - } - - setRecovery(); - service.removeViewFromParent(); - final Intent intent = NavigationHelper.getPlayerIntent( - service, - MainActivity.class, - this.getPlayQueue(), - this.getRepeatMode(), - this.getPlaybackSpeed(), - this.getPlaybackPitch(), - this.getPlaybackSkipSilence(), - null, - true, - !isPlaying(), - isMuted() - ); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - intent.putExtra(Constants.KEY_SERVICE_ID, - getCurrentMetadata().getMetadata().getServiceId()); - intent.putExtra(Constants.KEY_LINK_TYPE, StreamingService.LinkType.STREAM); - intent.putExtra(Constants.KEY_URL, getVideoUrl()); - intent.putExtra(Constants.KEY_TITLE, getVideoTitle()); - intent.putExtra(VideoDetailFragment.KEY_SWITCHING_PLAYERS, true); - service.onDestroy(); - context.startActivity(intent); - } - @Override public void onClick(final View v) { super.onClick(v); @@ -817,7 +785,9 @@ public void onClick(final View v) { } else if (v.getId() == openInBrowser.getId()) { onOpenInBrowserClicked(); } else if (v.getId() == fullscreenButton.getId()) { - switchFromPopupToMain(); + setRecovery(); + NavigationHelper.playOnMainPlayer(context, getPlayQueue(), true); + return; } else if (v.getId() == screenRotationButton.getId()) { // Only if it's not a vertical video or vertical video but in landscape with locked // orientation a screen orientation can be changed automatically diff --git a/app/src/main/java/org/schabi/newpipe/player/event/BasePlayerGestureListener.kt b/app/src/main/java/org/schabi/newpipe/player/event/BasePlayerGestureListener.kt index dcc1bb12893..681c1b9af46 100644 --- a/app/src/main/java/org/schabi/newpipe/player/event/BasePlayerGestureListener.kt +++ b/app/src/main/java/org/schabi/newpipe/player/event/BasePlayerGestureListener.kt @@ -63,7 +63,7 @@ abstract class BasePlayerGestureListener( private var isMovingInPopup = false private var isResizing = false - private val tossFlingVelocity = PlayerHelper.getTossFlingVelocity(service) + private val tossFlingVelocity = PlayerHelper.getTossFlingVelocity() // [popup] initial coordinates and distance between fingers private var initPointerDistance = -1.0 @@ -104,9 +104,6 @@ abstract class BasePlayerGestureListener( } private fun onTouchInPopup(v: View, event: MotionEvent): Boolean { - if (playerImpl == null) { - return false - } playerImpl.gestureDetector.onTouchEvent(event) if (event.pointerCount == 2 && !isMovingInPopup && !isResizing) { if (DEBUG) { diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/AudioReactor.java b/app/src/main/java/org/schabi/newpipe/player/helper/AudioReactor.java index a931c46bd87..ffe19599d20 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/AudioReactor.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/AudioReactor.java @@ -164,7 +164,7 @@ public void onAnimationEnd(final Animator animation) { @Override public void onAudioSessionId(final EventTime eventTime, final int audioSessionId) { - if (!PlayerHelper.isUsingDSP(context)) { + if (!PlayerHelper.isUsingDSP()) { return; } diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java index 4b52aa27d38..cdd07ba1cb5 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java @@ -295,7 +295,7 @@ public static int getPlaybackOptimalBufferMs() { return 60000; } - public static TrackSelection.Factory getQualitySelector(@NonNull final Context context) { + public static TrackSelection.Factory getQualitySelector() { return new AdaptiveTrackSelection.Factory( 1000, AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS, @@ -303,11 +303,11 @@ public static TrackSelection.Factory getQualitySelector(@NonNull final Context c AdaptiveTrackSelection.DEFAULT_BANDWIDTH_FRACTION); } - public static boolean isUsingDSP(@NonNull final Context context) { + public static boolean isUsingDSP() { return true; } - public static int getTossFlingVelocity(@NonNull final Context context) { + public static int getTossFlingVelocity() { return 2500; } diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHolder.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHolder.java index 6d0f5fff7b3..5764b2b946b 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHolder.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHolder.java @@ -49,6 +49,13 @@ public static MainPlayer.PlayerType getType() { return player.getPlayerType(); } + public static boolean isPlaying() { + if (player == null) { + return false; + } + return player.isPlaying(); + } + public static void setListener(final PlayerServiceExtendedEventListener newListener) { listener = newListener; // Force reload data from service diff --git a/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueueItem.java b/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueueItem.java index 74aef07fadb..79efc03aeea 100644 --- a/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueueItem.java +++ b/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueueItem.java @@ -64,6 +64,20 @@ private PlayQueueItem(@Nullable final String name, @Nullable final String url, this.recoveryPosition = RECOVERY_UNSET; } + @Override + public boolean equals(final Object o) { + if (o instanceof PlayQueueItem) { + return url.equals(((PlayQueueItem) o).url); + } else { + return false; + } + } + + @Override + public int hashCode() { + return url.hashCode(); + } + @NonNull public String getTitle() { return title; 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 a9673055232..3c791d44d1e 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -37,7 +37,6 @@ import org.schabi.newpipe.fragments.MainFragment; import org.schabi.newpipe.fragments.detail.VideoDetailFragment; import org.schabi.newpipe.fragments.list.channel.ChannelFragment; -import org.schabi.newpipe.fragments.list.comments.CommentsFragment; import org.schabi.newpipe.fragments.list.kiosk.KioskFragment; import org.schabi.newpipe.fragments.list.playlist.PlaylistFragment; import org.schabi.newpipe.fragments.list.search.SearchFragment; @@ -73,7 +72,6 @@ private NavigationHelper() { } public static Intent getPlayerIntent(@NonNull final Context context, @NonNull final Class targetClazz, @Nullable final PlayQueue playQueue, - @Nullable final String quality, final boolean resumePlayback) { final Intent intent = new Intent(context, targetClazz); @@ -83,9 +81,6 @@ public static Intent getPlayerIntent(@NonNull final Context context, intent.putExtra(VideoPlayer.PLAY_QUEUE_KEY, cacheKey); } } - if (quality != null) { - intent.putExtra(VideoPlayer.PLAYBACK_QUALITY, quality); - } intent.putExtra(VideoPlayer.RESUME_PLAYBACK, resumePlayback); intent.putExtra(VideoPlayer.PLAYER_TYPE, VideoPlayer.PLAYER_TYPE_VIDEO); @@ -96,8 +91,10 @@ public static Intent getPlayerIntent(@NonNull final Context context, public static Intent getPlayerIntent(@NonNull final Context context, @NonNull final Class targetClazz, @Nullable final PlayQueue playQueue, - final boolean resumePlayback) { - return getPlayerIntent(context, targetClazz, playQueue, null, resumePlayback); + final boolean resumePlayback, + final boolean playWhenReady) { + return getPlayerIntent(context, targetClazz, playQueue, resumePlayback) + .putExtra(BasePlayer.PLAY_WHEN_READY, playWhenReady); } @NonNull @@ -111,24 +108,6 @@ public static Intent getPlayerEnqueueIntent(@NonNull final Context context, .putExtra(BasePlayer.SELECT_ON_APPEND, selectOnAppend); } - @NonNull - public static Intent getPlayerIntent(@NonNull final Context context, - @NonNull final Class targetClazz, - @Nullable final PlayQueue playQueue, - final int repeatMode, - final float playbackSpeed, - final float playbackPitch, - final boolean playbackSkipSilence, - @Nullable final String playbackQuality, - final boolean resumePlayback, - final boolean startPaused, - final boolean isMuted) { - return getPlayerIntent(context, targetClazz, playQueue, playbackQuality, resumePlayback) - .putExtra(BasePlayer.REPEAT_MODE, repeatMode) - .putExtra(BasePlayer.START_PAUSED, startPaused) - .putExtra(BasePlayer.IS_MUTED, isMuted); - } - public static void playOnMainPlayer(final AppCompatActivity activity, @NonNull final PlayQueue playQueue) { final PlayQueueItem item = playQueue.getItem(); @@ -138,10 +117,12 @@ public static void playOnMainPlayer(final AppCompatActivity activity, } public static void playOnMainPlayer(final Context context, - @NonNull final PlayQueue playQueue) { + @NonNull final PlayQueue playQueue, + final boolean switchingPlayers) { final PlayQueueItem item = playQueue.getItem(); assert item != null; - openVideoDetail(context, item.getServiceId(), item.getUrl(), item.getTitle(), playQueue); + openVideoDetail(context, + item.getServiceId(), item.getUrl(), item.getTitle(), playQueue, switchingPlayers); } public static void playOnPopupPlayer(final Context context, @@ -370,7 +351,7 @@ public static void openVideoDetailFragment(@NonNull final Context context, autoPlay = PlayerHelper.isAutoplayAllowedByUser(context); } else if (switchingPlayers) { // switching player to main player - autoPlay = true; + autoPlay = PlayerHolder.isPlaying(); // keep play/pause state } else if (playerType == MainPlayer.PlayerType.VIDEO) { // opening new stream while already playing in main player autoPlay = PlayerHelper.isAutoplayAllowedByUser(context); @@ -416,16 +397,6 @@ public static void openChannelFragment(final FragmentManager fragmentManager, .commit(); } - public static void openCommentsFragment(final FragmentManager fragmentManager, - final int serviceId, final String url, - @NonNull final String name) { - fragmentManager.beginTransaction() - .setCustomAnimations(R.anim.switch_service_in, R.anim.switch_service_out) - .replace(R.id.fragment_holder, CommentsFragment.getInstance(serviceId, url, name)) - .addToBackStack(null) - .commit(); - } - public static void openPlaylistFragment(final FragmentManager fragmentManager, final int serviceId, final String url, @NonNull final String name) { @@ -506,23 +477,17 @@ public static void openSearch(final Context context, final int serviceId, context.startActivity(mIntent); } - public static void openChannel(final Context context, final int serviceId, - final String url, @NonNull final String name) { - final Intent openIntent = getOpenIntent(context, url, serviceId, - StreamingService.LinkType.CHANNEL); - openIntent.putExtra(Constants.KEY_TITLE, name); - context.startActivity(openIntent); - } - public static void openVideoDetail(final Context context, final int serviceId, final String url, @NonNull final String title, - @Nullable final PlayQueue playQueue) { + @Nullable final PlayQueue playQueue, + final boolean switchingPlayers) { final Intent intent = getOpenIntent(context, url, serviceId, StreamingService.LinkType.STREAM); intent.putExtra(Constants.KEY_TITLE, title); + intent.putExtra(VideoDetailFragment.KEY_SWITCHING_PLAYERS, switchingPlayers); if (playQueue != null) { final String cacheKey = SerializedCache.getInstance().put(playQueue, PlayQueue.class);