More fixes with opening VideoDetailFragment

This commit is contained in:
Stypox 2020-10-31 20:26:09 +01:00
parent bb882ada2c
commit 2a2c82e73b
No known key found for this signature in database
GPG key ID: 4BDF1B40A49FDD23
13 changed files with 87 additions and 170 deletions

View file

@ -685,7 +685,7 @@ public class RouterActivity extends AppCompatActivity {
} }
if (choice.playerChoice.equals(videoPlayerKey)) { if (choice.playerChoice.equals(videoPlayerKey)) {
NavigationHelper.playOnMainPlayer(this, playQueue); NavigationHelper.playOnMainPlayer(this, playQueue, false);
} else if (choice.playerChoice.equals(backgroundPlayerKey)) { } else if (choice.playerChoice.equals(backgroundPlayerKey)) {
NavigationHelper.playOnBackgroundPlayer(this, playQueue, true); NavigationHelper.playOnBackgroundPlayer(this, playQueue, true);
} else if (choice.playerChoice.equals(popupPlayerKey)) { } else if (choice.playerChoice.equals(popupPlayerKey)) {

View file

@ -1097,7 +1097,7 @@ public final class VideoDetailFragment
private void openMainPlayer() { private void openMainPlayer() {
if (playerService == null) { if (playerService == null) {
PlayerHolder.startService(App.getApp(), true, this); PlayerHolder.startService(App.getApp(), autoPlayEnabled, this);
return; return;
} }
if (currentInfo == null) { if (currentInfo == null) {
@ -1112,7 +1112,7 @@ public final class VideoDetailFragment
addVideoPlayerView(); addVideoPlayerView();
final Intent playerIntent = NavigationHelper final Intent playerIntent = NavigationHelper
.getPlayerIntent(requireContext(), MainPlayer.class, queue, null, true); .getPlayerIntent(requireContext(), MainPlayer.class, queue, true, autoPlayEnabled);
activity.startService(playerIntent); activity.startService(playerIntent);
} }

View file

@ -2,11 +2,8 @@ package org.schabi.newpipe.player;
import android.content.Intent; import android.content.Intent;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.PermissionHelper;
public final class BackgroundPlayerActivity extends ServicePlayerActivity { public final class BackgroundPlayerActivity extends ServicePlayerActivity {
@ -46,31 +43,6 @@ public final class BackgroundPlayerActivity extends ServicePlayerActivity {
return R.menu.menu_play_queue_bg; 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 @Override
public void setupMenu(final Menu menu) { public void setupMenu(final Menu menu) {
if (player == null) { if (player == null) {

View file

@ -125,7 +125,7 @@ public abstract class BasePlayer implements
@NonNull @NonNull
public static final String RESUME_PLAYBACK = "resume_playback"; public static final String RESUME_PLAYBACK = "resume_playback";
@NonNull @NonNull
public static final String START_PAUSED = "start_paused"; public static final String PLAY_WHEN_READY = "play_when_ready";
@NonNull @NonNull
public static final String SELECT_ON_APPEND = "select_on_append"; public static final String SELECT_ON_APPEND = "select_on_append";
@NonNull @NonNull
@ -224,7 +224,7 @@ public abstract class BasePlayer implements
this.dataSource = new PlayerDataSource(context, userAgent, bandwidthMeter); this.dataSource = new PlayerDataSource(context, userAgent, bandwidthMeter);
final TrackSelection.Factory trackSelectionFactory = PlayerHelper final TrackSelection.Factory trackSelectionFactory = PlayerHelper
.getQualitySelector(context); .getQualitySelector();
this.trackSelector = new CustomTrackSelector(context, trackSelectionFactory); this.trackSelector = new CustomTrackSelector(context, trackSelectionFactory);
this.loadControl = new LoadController(); this.loadControl = new LoadController();
@ -302,6 +302,7 @@ public abstract class BasePlayer implements
final boolean samePlayQueue = playQueue != null && playQueue.equals(queue); final boolean samePlayQueue = playQueue != null && playQueue.equals(queue);
final int repeatMode = intent.getIntExtra(REPEAT_MODE, getRepeatMode()); final int repeatMode = intent.getIntExtra(REPEAT_MODE, getRepeatMode());
final boolean playWhenReady = intent.getBooleanExtra(PLAY_WHEN_READY, true);
final boolean isMuted = intent final boolean isMuted = intent
.getBooleanExtra(IS_MUTED, simpleExoPlayer != null && isMuted()); .getBooleanExtra(IS_MUTED, simpleExoPlayer != null && isMuted());
@ -327,16 +328,20 @@ public abstract class BasePlayer implements
simpleExoPlayer.retry(); simpleExoPlayer.retry();
} }
simpleExoPlayer.seekTo(playQueue.getIndex(), queue.getItem().getRecoveryPosition()); 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 // Do not re-init the same PlayQueue. Save time
// Player can have state = IDLE when playback is stopped or failed // Player can have state = IDLE when playback is stopped or failed
// and we should retry() in this case // and we should retry() in this case
if (simpleExoPlayer.getPlaybackState() == Player.STATE_IDLE) { if (simpleExoPlayer.getPlaybackState() == Player.STATE_IDLE) {
simpleExoPlayer.retry(); simpleExoPlayer.retry();
} }
return; simpleExoPlayer.setPlayWhenReady(playWhenReady);
} else if (intent.getBooleanExtra(RESUME_PLAYBACK, false) } else if (intent.getBooleanExtra(RESUME_PLAYBACK, false)
&& isPlaybackResumeEnabled() && isPlaybackResumeEnabled()
&& !samePlayQueue) { && !samePlayQueue) {
@ -351,7 +356,7 @@ public abstract class BasePlayer implements
state -> { state -> {
queue.setRecovery(queue.getIndex(), state.getProgressTime()); queue.setRecovery(queue.getIndex(), state.getProgressTime());
initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, initPlayback(queue, repeatMode, playbackSpeed, playbackPitch,
playbackSkipSilence, true, isMuted); playbackSkipSilence, playWhenReady, isMuted);
}, },
error -> { error -> {
if (DEBUG) { if (DEBUG) {
@ -359,24 +364,22 @@ public abstract class BasePlayer implements
} }
// In case any error we can start playback without history // In case any error we can start playback without history
initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, initPlayback(queue, repeatMode, playbackSpeed, playbackPitch,
playbackSkipSilence, true, isMuted); playbackSkipSilence, playWhenReady, isMuted);
}, },
() -> { () -> {
// Completed but not found in history // Completed but not found in history
initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, initPlayback(queue, repeatMode, playbackSpeed, playbackPitch,
playbackSkipSilence, true, isMuted); playbackSkipSilence, playWhenReady, isMuted);
} }
); );
databaseUpdateReactor.add(stateLoader); 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() { private PlaybackParameters retrievePlaybackParametersFromPreferences() {

View file

@ -240,7 +240,7 @@ public final class MainPlayer extends Service {
} }
public void removeViewFromParent() { public void removeViewFromParent() {
if (getView().getParent() != null) { if (getView() != null && getView().getParent() != null) {
if (playerImpl.getParentActivity() != null) { if (playerImpl.getParentActivity() != null) {
// This means view was added to fragment // This means view was added to fragment
final ViewGroup parent = (ViewGroup) getView().getParent(); final ViewGroup parent = (ViewGroup) getView().getParent();

View file

@ -27,9 +27,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.google.android.exoplayer2.PlaybackParameters; import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player;
import org.schabi.newpipe.MainActivity;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.fragments.OnScrollBelowItemsListener; import org.schabi.newpipe.fragments.OnScrollBelowItemsListener;
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
@ -42,9 +40,9 @@ import org.schabi.newpipe.player.playqueue.PlayQueueItem;
import org.schabi.newpipe.player.playqueue.PlayQueueItemBuilder; import org.schabi.newpipe.player.playqueue.PlayQueueItemBuilder;
import org.schabi.newpipe.player.playqueue.PlayQueueItemHolder; import org.schabi.newpipe.player.playqueue.PlayQueueItemHolder;
import org.schabi.newpipe.player.playqueue.PlayQueueItemTouchCallback; import org.schabi.newpipe.player.playqueue.PlayQueueItemTouchCallback;
import org.schabi.newpipe.util.Constants;
import org.schabi.newpipe.util.Localization; import org.schabi.newpipe.util.Localization;
import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.PermissionHelper;
import org.schabi.newpipe.util.ThemeHelper; import org.schabi.newpipe.util.ThemeHelper;
import java.util.Collections; import java.util.Collections;
@ -113,9 +111,8 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
public abstract int getPlayerOptionMenuResource(); public abstract int getPlayerOptionMenuResource();
public abstract boolean onPlayerOptionSelected(MenuItem item);
public abstract void setupMenu(Menu m); public abstract void setupMenu(Menu m);
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Activity Lifecycle // Activity Lifecycle
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
@ -187,12 +184,22 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
return true; return true;
case R.id.action_switch_main: case R.id.action_switch_main:
this.player.setRecovery(); this.player.setRecovery();
getApplicationContext().startActivity( NavigationHelper.playOnMainPlayer(this, player.getPlayQueue(), true);
getSwitchIntent(MainActivity.class, MainPlayer.PlayerType.VIDEO) return true;
.putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying())); 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 true;
} }
return onPlayerOptionSelected(item) || super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@Override @Override
@ -201,24 +208,6 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
unbind(); 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 // Service Connection
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
@ -368,8 +357,8 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
Menu.NONE, R.string.play_queue_stream_detail); Menu.NONE, R.string.play_queue_stream_detail);
detail.setOnMenuItemClickListener(menuItem -> { detail.setOnMenuItemClickListener(menuItem -> {
// playQueue is null since we don't want any queue change // playQueue is null since we don't want any queue change
NavigationHelper.openVideoDetail( NavigationHelper.openVideoDetail(this, item.getServiceId(), item.getUrl(),
this, item.getServiceId(), item.getUrl(), item.getTitle(), null); item.getTitle(), null, false);
return true; return true;
}); });

View file

@ -76,9 +76,7 @@ import com.google.android.exoplayer2.ui.SubtitleView;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.nostra13.universalimageloader.core.assist.FailReason; import com.nostra13.universalimageloader.core.assist.FailReason;
import org.schabi.newpipe.MainActivity;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.extractor.stream.VideoStream; import org.schabi.newpipe.extractor.stream.VideoStream;
import org.schabi.newpipe.fragments.OnScrollBelowItemsListener; import org.schabi.newpipe.fragments.OnScrollBelowItemsListener;
@ -97,7 +95,6 @@ import org.schabi.newpipe.player.resolver.AudioPlaybackResolver;
import org.schabi.newpipe.player.resolver.MediaSourceTag; import org.schabi.newpipe.player.resolver.MediaSourceTag;
import org.schabi.newpipe.player.resolver.VideoPlaybackResolver; import org.schabi.newpipe.player.resolver.VideoPlaybackResolver;
import org.schabi.newpipe.util.AnimationUtils; import org.schabi.newpipe.util.AnimationUtils;
import org.schabi.newpipe.util.Constants;
import org.schabi.newpipe.util.DeviceUtils; import org.schabi.newpipe.util.DeviceUtils;
import org.schabi.newpipe.util.KoreUtil; import org.schabi.newpipe.util.KoreUtil;
import org.schabi.newpipe.util.ListHelper; import org.schabi.newpipe.util.ListHelper;
@ -260,7 +257,12 @@ public class VideoPlayerImpl extends VideoPlayer
onQueueClosed(); onQueueClosed();
// Android TV: without it focus will frame the whole player // Android TV: without it focus will frame the whole player
playPauseButton.requestFocus(); playPauseButton.requestFocus();
onPlay();
if (simpleExoPlayer.getPlayWhenReady()) {
onPlay();
} else {
onPause();
}
} }
NavigationHelper.sendPlayerStartedEvent(service); NavigationHelper.sendPlayerStartedEvent(service);
} }
@ -756,40 +758,6 @@ public class VideoPlayerImpl extends VideoPlayer
setupScreenRotationButton(); 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 @Override
public void onClick(final View v) { public void onClick(final View v) {
super.onClick(v); super.onClick(v);
@ -817,7 +785,9 @@ public class VideoPlayerImpl extends VideoPlayer
} else if (v.getId() == openInBrowser.getId()) { } else if (v.getId() == openInBrowser.getId()) {
onOpenInBrowserClicked(); onOpenInBrowserClicked();
} else if (v.getId() == fullscreenButton.getId()) { } else if (v.getId() == fullscreenButton.getId()) {
switchFromPopupToMain(); setRecovery();
NavigationHelper.playOnMainPlayer(context, getPlayQueue(), true);
return;
} else if (v.getId() == screenRotationButton.getId()) { } else if (v.getId() == screenRotationButton.getId()) {
// Only if it's not a vertical video or vertical video but in landscape with locked // Only if it's not a vertical video or vertical video but in landscape with locked
// orientation a screen orientation can be changed automatically // orientation a screen orientation can be changed automatically

View file

@ -63,7 +63,7 @@ abstract class BasePlayerGestureListener(
private var isMovingInPopup = false private var isMovingInPopup = false
private var isResizing = false private var isResizing = false
private val tossFlingVelocity = PlayerHelper.getTossFlingVelocity(service) private val tossFlingVelocity = PlayerHelper.getTossFlingVelocity()
// [popup] initial coordinates and distance between fingers // [popup] initial coordinates and distance between fingers
private var initPointerDistance = -1.0 private var initPointerDistance = -1.0
@ -104,9 +104,6 @@ abstract class BasePlayerGestureListener(
} }
private fun onTouchInPopup(v: View, event: MotionEvent): Boolean { private fun onTouchInPopup(v: View, event: MotionEvent): Boolean {
if (playerImpl == null) {
return false
}
playerImpl.gestureDetector.onTouchEvent(event) playerImpl.gestureDetector.onTouchEvent(event)
if (event.pointerCount == 2 && !isMovingInPopup && !isResizing) { if (event.pointerCount == 2 && !isMovingInPopup && !isResizing) {
if (DEBUG) { if (DEBUG) {

View file

@ -164,7 +164,7 @@ public class AudioReactor implements AudioManager.OnAudioFocusChangeListener, An
@Override @Override
public void onAudioSessionId(final EventTime eventTime, final int audioSessionId) { public void onAudioSessionId(final EventTime eventTime, final int audioSessionId) {
if (!PlayerHelper.isUsingDSP(context)) { if (!PlayerHelper.isUsingDSP()) {
return; return;
} }

View file

@ -295,7 +295,7 @@ public final class PlayerHelper {
return 60000; return 60000;
} }
public static TrackSelection.Factory getQualitySelector(@NonNull final Context context) { public static TrackSelection.Factory getQualitySelector() {
return new AdaptiveTrackSelection.Factory( return new AdaptiveTrackSelection.Factory(
1000, 1000,
AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS, AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
@ -303,11 +303,11 @@ public final class PlayerHelper {
AdaptiveTrackSelection.DEFAULT_BANDWIDTH_FRACTION); AdaptiveTrackSelection.DEFAULT_BANDWIDTH_FRACTION);
} }
public static boolean isUsingDSP(@NonNull final Context context) { public static boolean isUsingDSP() {
return true; return true;
} }
public static int getTossFlingVelocity(@NonNull final Context context) { public static int getTossFlingVelocity() {
return 2500; return 2500;
} }

View file

@ -49,6 +49,13 @@ public final class PlayerHolder {
return player.getPlayerType(); return player.getPlayerType();
} }
public static boolean isPlaying() {
if (player == null) {
return false;
}
return player.isPlaying();
}
public static void setListener(final PlayerServiceExtendedEventListener newListener) { public static void setListener(final PlayerServiceExtendedEventListener newListener) {
listener = newListener; listener = newListener;
// Force reload data from service // Force reload data from service

View file

@ -64,6 +64,20 @@ public class PlayQueueItem implements Serializable {
this.recoveryPosition = RECOVERY_UNSET; 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 @NonNull
public String getTitle() { public String getTitle() {
return title; return title;

View file

@ -37,7 +37,6 @@ import org.schabi.newpipe.extractor.stream.VideoStream;
import org.schabi.newpipe.fragments.MainFragment; import org.schabi.newpipe.fragments.MainFragment;
import org.schabi.newpipe.fragments.detail.VideoDetailFragment; import org.schabi.newpipe.fragments.detail.VideoDetailFragment;
import org.schabi.newpipe.fragments.list.channel.ChannelFragment; 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.kiosk.KioskFragment;
import org.schabi.newpipe.fragments.list.playlist.PlaylistFragment; import org.schabi.newpipe.fragments.list.playlist.PlaylistFragment;
import org.schabi.newpipe.fragments.list.search.SearchFragment; import org.schabi.newpipe.fragments.list.search.SearchFragment;
@ -73,7 +72,6 @@ public final class NavigationHelper {
public static <T> Intent getPlayerIntent(@NonNull final Context context, public static <T> Intent getPlayerIntent(@NonNull final Context context,
@NonNull final Class<T> targetClazz, @NonNull final Class<T> targetClazz,
@Nullable final PlayQueue playQueue, @Nullable final PlayQueue playQueue,
@Nullable final String quality,
final boolean resumePlayback) { final boolean resumePlayback) {
final Intent intent = new Intent(context, targetClazz); final Intent intent = new Intent(context, targetClazz);
@ -83,9 +81,6 @@ public final class NavigationHelper {
intent.putExtra(VideoPlayer.PLAY_QUEUE_KEY, cacheKey); 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.RESUME_PLAYBACK, resumePlayback);
intent.putExtra(VideoPlayer.PLAYER_TYPE, VideoPlayer.PLAYER_TYPE_VIDEO); intent.putExtra(VideoPlayer.PLAYER_TYPE, VideoPlayer.PLAYER_TYPE_VIDEO);
@ -96,8 +91,10 @@ public final class NavigationHelper {
public static <T> Intent getPlayerIntent(@NonNull final Context context, public static <T> Intent getPlayerIntent(@NonNull final Context context,
@NonNull final Class<T> targetClazz, @NonNull final Class<T> targetClazz,
@Nullable final PlayQueue playQueue, @Nullable final PlayQueue playQueue,
final boolean resumePlayback) { final boolean resumePlayback,
return getPlayerIntent(context, targetClazz, playQueue, null, resumePlayback); final boolean playWhenReady) {
return getPlayerIntent(context, targetClazz, playQueue, resumePlayback)
.putExtra(BasePlayer.PLAY_WHEN_READY, playWhenReady);
} }
@NonNull @NonNull
@ -111,24 +108,6 @@ public final class NavigationHelper {
.putExtra(BasePlayer.SELECT_ON_APPEND, selectOnAppend); .putExtra(BasePlayer.SELECT_ON_APPEND, selectOnAppend);
} }
@NonNull
public static <T> Intent getPlayerIntent(@NonNull final Context context,
@NonNull final Class<T> 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, public static void playOnMainPlayer(final AppCompatActivity activity,
@NonNull final PlayQueue playQueue) { @NonNull final PlayQueue playQueue) {
final PlayQueueItem item = playQueue.getItem(); final PlayQueueItem item = playQueue.getItem();
@ -138,10 +117,12 @@ public final class NavigationHelper {
} }
public static void playOnMainPlayer(final Context context, public static void playOnMainPlayer(final Context context,
@NonNull final PlayQueue playQueue) { @NonNull final PlayQueue playQueue,
final boolean switchingPlayers) {
final PlayQueueItem item = playQueue.getItem(); final PlayQueueItem item = playQueue.getItem();
assert item != null; 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, public static void playOnPopupPlayer(final Context context,
@ -370,7 +351,7 @@ public final class NavigationHelper {
autoPlay = PlayerHelper.isAutoplayAllowedByUser(context); autoPlay = PlayerHelper.isAutoplayAllowedByUser(context);
} else if (switchingPlayers) { } else if (switchingPlayers) {
// switching player to main player // switching player to main player
autoPlay = true; autoPlay = PlayerHolder.isPlaying(); // keep play/pause state
} else if (playerType == MainPlayer.PlayerType.VIDEO) { } else if (playerType == MainPlayer.PlayerType.VIDEO) {
// opening new stream while already playing in main player // opening new stream while already playing in main player
autoPlay = PlayerHelper.isAutoplayAllowedByUser(context); autoPlay = PlayerHelper.isAutoplayAllowedByUser(context);
@ -416,16 +397,6 @@ public final class NavigationHelper {
.commit(); .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, public static void openPlaylistFragment(final FragmentManager fragmentManager,
final int serviceId, final String url, final int serviceId, final String url,
@NonNull final String name) { @NonNull final String name) {
@ -506,23 +477,17 @@ public final class NavigationHelper {
context.startActivity(mIntent); 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, public static void openVideoDetail(final Context context,
final int serviceId, final int serviceId,
final String url, final String url,
@NonNull final String title, @NonNull final String title,
@Nullable final PlayQueue playQueue) { @Nullable final PlayQueue playQueue,
final boolean switchingPlayers) {
final Intent intent = getOpenIntent(context, url, serviceId, final Intent intent = getOpenIntent(context, url, serviceId,
StreamingService.LinkType.STREAM); StreamingService.LinkType.STREAM);
intent.putExtra(Constants.KEY_TITLE, title); intent.putExtra(Constants.KEY_TITLE, title);
intent.putExtra(VideoDetailFragment.KEY_SWITCHING_PLAYERS, switchingPlayers);
if (playQueue != null) { if (playQueue != null) {
final String cacheKey = SerializedCache.getInstance().put(playQueue, PlayQueue.class); final String cacheKey = SerializedCache.getInstance().put(playQueue, PlayQueue.class);