mirror of
https://github.com/yuliskov/SmartTube.git
synced 2026-05-13 08:20:51 -05:00
video card: playback preview: upd 12
This commit is contained in:
+1
-1
Submodule MediaServiceCore updated: d0fda2afe2...2f70730743
+9
@@ -51,6 +51,11 @@ public abstract class BasePlayerController implements PlayerEventListener {
|
||||
return mMainController != null ? mMainController.getPlayer() : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Video getVideo() {
|
||||
return mMainController != null ? mMainController.getVideo() : null;
|
||||
}
|
||||
|
||||
protected void setAltContext(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
@@ -391,4 +396,8 @@ public abstract class BasePlayerController implements PlayerEventListener {
|
||||
protected boolean isEmbedPlayer() {
|
||||
return getPlayer() != null && getPlayer().isEmbed();
|
||||
}
|
||||
|
||||
protected boolean isSwitchFromEmbed() {
|
||||
return mMainController != null && mMainController.isSwitchFromEmbed();
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -35,13 +35,13 @@ public class ContentBlockController extends BasePlayerController {
|
||||
private static final long POLL_INTERVAL_MS = 1_000;
|
||||
private static final int CONTENT_BLOCK_ID = 144;
|
||||
private MediaItemService mMediaItemService;
|
||||
private Video mVideo;
|
||||
private List<SponsorSegment> mOriginalSegments;
|
||||
private List<SponsorSegment> mActiveSegments;
|
||||
private long mLastSkipPosMs;
|
||||
private boolean mSkipExclude;
|
||||
private Disposable mSegmentsAction;
|
||||
private Observable<List<SponsorSegment>> mCachedSegmentsAction;
|
||||
private String mVideoId;
|
||||
|
||||
public static class SegmentAction {
|
||||
public String segmentCategory;
|
||||
@@ -158,12 +158,12 @@ public class ContentBlockController extends BasePlayerController {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!item.equals(mVideo) || mCachedSegmentsAction == null) {
|
||||
if (!Helpers.equals(mVideoId, item.videoId) || mCachedSegmentsAction == null) {
|
||||
// NOTE: SponsorBlock (when happened java.net.SocketTimeoutException) could block whole application with Schedulers.io()
|
||||
// Because Schedulers.io() reuses blocked threads in RxJava 2: https://github.com/ReactiveX/RxJava/issues/6542
|
||||
mCachedSegmentsAction = mMediaItemService.getSponsorSegmentsObserve(item.videoId, getContentBlockData().getEnabledCategories())
|
||||
.cache();
|
||||
mVideo = item;
|
||||
mVideoId = item.videoId;
|
||||
}
|
||||
|
||||
mSegmentsAction = mCachedSegmentsAction
|
||||
@@ -207,7 +207,7 @@ public class ContentBlockController extends BasePlayerController {
|
||||
}
|
||||
|
||||
private void skipSegment(long interval) {
|
||||
if (mActiveSegments == null || mActiveSegments.isEmpty() || !Video.equals(mVideo, getPlayer().getVideo())) {
|
||||
if (mActiveSegments == null || mActiveSegments.isEmpty() || !Helpers.equals(mVideoId, getVideo())) {
|
||||
disposeActions();
|
||||
return;
|
||||
}
|
||||
|
||||
+11
-14
@@ -35,7 +35,6 @@ public class RemoteController extends BasePlayerController implements OnDataChan
|
||||
private Disposable mPostStartPlayAction;
|
||||
private Disposable mPostStateAction;
|
||||
private Disposable mPostVolumeAction;
|
||||
private Video mVideo;
|
||||
private boolean mConnected;
|
||||
private long mNewVideoPositionMs;
|
||||
private Disposable mActionDown;
|
||||
@@ -83,9 +82,8 @@ public class RemoteController extends BasePlayerController implements OnDataChan
|
||||
}
|
||||
|
||||
postStartPlaying(item, getPlayer().getPlayWhenReady());
|
||||
mVideo = item;
|
||||
if (mConnected) {
|
||||
mRemoteControlData.setLastVideo(mVideo);
|
||||
mRemoteControlData.setLastVideo(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +122,6 @@ public class RemoteController extends BasePlayerController implements OnDataChan
|
||||
public void onFinish() {
|
||||
// User action detected. Hide remote playlist.
|
||||
mConnected = false;
|
||||
mVideo = null;
|
||||
}
|
||||
|
||||
private void postStartPlaying(@Nullable Video item, boolean isPlaying) {
|
||||
@@ -326,7 +323,7 @@ public class RemoteController extends BasePlayerController implements OnDataChan
|
||||
getPlayer().setPositionMs(command.getCurrentTimeMs());
|
||||
postSeek(command.getCurrentTimeMs());
|
||||
} else {
|
||||
openNewVideo(mVideo);
|
||||
openNewVideo(getVideo());
|
||||
}
|
||||
break;
|
||||
case Command.TYPE_PLAY:
|
||||
@@ -337,7 +334,7 @@ public class RemoteController extends BasePlayerController implements OnDataChan
|
||||
postPlay(true);
|
||||
} else {
|
||||
// Already connected
|
||||
openNewVideo(mVideo != null ? mVideo : mRemoteControlData.getLastVideo());
|
||||
openNewVideo(getVideo() != null ? getVideo() : mRemoteControlData.getLastVideo());
|
||||
}
|
||||
break;
|
||||
case Command.TYPE_PAUSE:
|
||||
@@ -348,7 +345,7 @@ public class RemoteController extends BasePlayerController implements OnDataChan
|
||||
postPlay(false);
|
||||
} else {
|
||||
// Already connected
|
||||
openNewVideo(mVideo != null ? mVideo : mRemoteControlData.getLastVideo());
|
||||
openNewVideo(getVideo() != null ? getVideo() : mRemoteControlData.getLastVideo());
|
||||
}
|
||||
break;
|
||||
case Command.TYPE_NEXT:
|
||||
@@ -356,7 +353,7 @@ public class RemoteController extends BasePlayerController implements OnDataChan
|
||||
movePlayerToForeground();
|
||||
getController(VideoLoaderController.class).loadNext();
|
||||
} else {
|
||||
openNewVideo(mVideo);
|
||||
openNewVideo(getVideo());
|
||||
}
|
||||
break;
|
||||
case Command.TYPE_PREVIOUS:
|
||||
@@ -365,7 +362,7 @@ public class RemoteController extends BasePlayerController implements OnDataChan
|
||||
// Switch immediately. Skip position reset logic.
|
||||
getController(VideoLoaderController.class).loadPrevious();
|
||||
} else {
|
||||
openNewVideo(mVideo);
|
||||
openNewVideo(getVideo());
|
||||
}
|
||||
break;
|
||||
case Command.TYPE_GET_STATE:
|
||||
@@ -486,15 +483,15 @@ public class RemoteController extends BasePlayerController implements OnDataChan
|
||||
}
|
||||
|
||||
private void openNewVideo(Video newVideo) {
|
||||
if (Video.equals(mVideo, newVideo) && getViewManager().isPlayerInForeground()) { // same video already playing
|
||||
//mVideo.playlistId = newVideo.playlistId;
|
||||
//mVideo.playlistIndex = newVideo.playlistIndex;
|
||||
//mVideo.playlistParams = newVideo.playlistParams;
|
||||
if (Video.equals(getVideo(), newVideo) && getViewManager().isPlayerInForeground()) { // same video already playing
|
||||
//getVideo().playlistId = newVideo.playlistId;
|
||||
//getVideo().playlistIndex = newVideo.playlistIndex;
|
||||
//getVideo().playlistParams = newVideo.playlistParams;
|
||||
if (mNewVideoPositionMs > 0) {
|
||||
getPlayer().setPositionMs(mNewVideoPositionMs);
|
||||
mNewVideoPositionMs = 0;
|
||||
}
|
||||
postStartPlaying(mVideo, getPlayer().isPlaying());
|
||||
postStartPlaying(getVideo(), getPlayer().isPlaying());
|
||||
} else if (newVideo != null) {
|
||||
newVideo.isRemote = true;
|
||||
getPlaybackPresenter().openVideo(newVideo);
|
||||
|
||||
-1
@@ -27,7 +27,6 @@ import com.liskovsoft.smartyoutubetv2.common.app.presenters.PlaybackPresenter;
|
||||
import com.liskovsoft.smartyoutubetv2.common.misc.DeArrowProcessor;
|
||||
import com.liskovsoft.smartyoutubetv2.common.misc.MediaServiceManager;
|
||||
import com.liskovsoft.smartyoutubetv2.common.prefs.GeneralData;
|
||||
import com.liskovsoft.smartyoutubetv2.common.prefs.PlayerTweaksData;
|
||||
import com.liskovsoft.smartyoutubetv2.common.utils.Utils;
|
||||
import com.liskovsoft.youtubeapi.service.YouTubeServiceManager;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
+34
-32
@@ -45,7 +45,7 @@ public class VideoLoaderController extends BasePlayerController implements OnDat
|
||||
private static final long BUFFERING_RECURRENCE_COUNT = (long) (BUFFERING_WINDOW_MS * 0.5 / BUFFERING_THRESHOLD_MS);
|
||||
private final Playlist mPlaylist;
|
||||
private final UniqueRandom mRandom;
|
||||
private Video mLastVideo;
|
||||
private Video mPendingVideo;
|
||||
private int mLastErrorType = -1;
|
||||
private SuggestionsController mSuggestionsController;
|
||||
private long mSleepTimerStartMs;
|
||||
@@ -53,7 +53,7 @@ public class VideoLoaderController extends BasePlayerController implements OnDat
|
||||
private Disposable mMpdStreamAction;
|
||||
private final Runnable mReloadVideo = () -> {
|
||||
getController(VideoStateController.class).saveState();
|
||||
loadVideo(mLastVideo);
|
||||
loadVideo(getVideo());
|
||||
};
|
||||
private final Runnable mLoadNext = this::loadNext;
|
||||
private final Runnable mMetadataSync = () -> {
|
||||
@@ -70,8 +70,9 @@ public class VideoLoaderController extends BasePlayerController implements OnDat
|
||||
private final Runnable mOnLongBuffering = this::updateBufferingCountIfNeeded;
|
||||
|
||||
private final Runnable mRebootApp = () -> {
|
||||
if (mLastVideo != null && mLastVideo.hasVideo()) {
|
||||
Utils.restartTheApp(getContext(), mLastVideo.videoId);
|
||||
Video video = getVideo();
|
||||
if (video != null && video.hasVideo()) {
|
||||
Utils.restartTheApp(getContext(), video.videoId);
|
||||
}
|
||||
};
|
||||
private final Runnable mOnApplyPlaybackMode = () -> {
|
||||
@@ -99,8 +100,7 @@ public class VideoLoaderController extends BasePlayerController implements OnDat
|
||||
return;
|
||||
}
|
||||
|
||||
boolean isVideoChanged = !item.equals(mLastVideo);
|
||||
mLastVideo = item; // save for later
|
||||
boolean isVideoChanged = !item.equals(getVideo());
|
||||
|
||||
if (!item.fromQueue) {
|
||||
mPlaylist.add(item);
|
||||
@@ -114,6 +114,8 @@ public class VideoLoaderController extends BasePlayerController implements OnDat
|
||||
} else {
|
||||
loadSuggestions(item); // update suggestions only
|
||||
}
|
||||
} else {
|
||||
mPendingVideo = item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,12 +125,12 @@ public class VideoLoaderController extends BasePlayerController implements OnDat
|
||||
}
|
||||
|
||||
private void onLongBuffering() {
|
||||
if (getPlayer() == null || mLastVideo == null) {
|
||||
if (getPlayer() == null || getVideo() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Stream end check (hangs on buffering)
|
||||
if ((!mLastVideo.isLive || mLastVideo.isLiveEnd) &&
|
||||
if ((!getVideo().isLive || getVideo().isLiveEnd) &&
|
||||
getPlayer().getDurationMs() - getPlayer().getPositionMs() < STREAM_END_THRESHOLD_MS) {
|
||||
getMainController().onPlayEnd();
|
||||
} else {
|
||||
@@ -144,11 +146,11 @@ public class VideoLoaderController extends BasePlayerController implements OnDat
|
||||
if (getPlayer() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Video video = getPlayer().getVideo();
|
||||
loadVideo(video != null ? video : mLastVideo);
|
||||
|
||||
loadVideo(Helpers.firstNonNull(mPendingVideo, getPlayer().getVideo(), getVideo()));
|
||||
getPlayer().setButtonState(R.id.action_repeat, getPlayerData().getPlaybackMode());
|
||||
mSleepTimerStartMs = System.currentTimeMillis();
|
||||
mPendingVideo = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -204,7 +206,7 @@ public class VideoLoaderController extends BasePlayerController implements OnDat
|
||||
|
||||
public void loadNext() {
|
||||
Video next = mSuggestionsController.getNext();
|
||||
//mLastVideo = null; // in case next video is the same as previous
|
||||
//getVideo() = null; // in case next video is the same as previous
|
||||
|
||||
if (next != null) {
|
||||
forceSectionPlaylistIfNeeded(getPlayer().getVideo(), next);
|
||||
@@ -249,7 +251,7 @@ public class VideoLoaderController extends BasePlayerController implements OnDat
|
||||
|
||||
// Remove error msg if needed
|
||||
if (getPlayerData().isSonyTimerFixEnabled()) {
|
||||
getPlayer().setVideo(mLastVideo);
|
||||
getPlayer().setVideo(getVideo());
|
||||
}
|
||||
|
||||
Utils.removeCallbacks(mRestartEngine);
|
||||
@@ -334,7 +336,7 @@ public class VideoLoaderController extends BasePlayerController implements OnDat
|
||||
|
||||
String bgImageUrl = null;
|
||||
|
||||
mLastVideo.sync(formatInfo);
|
||||
getVideo().sync(formatInfo);
|
||||
|
||||
// Fix stretched video for a couple milliseconds (before the onVideoSizeChanged gets called)
|
||||
applyAspectRatio(formatInfo);
|
||||
@@ -355,8 +357,8 @@ public class VideoLoaderController extends BasePlayerController implements OnDat
|
||||
|
||||
getPlayer().setTitle(formatInfo.getPlayabilityStatus());
|
||||
getPlayer().showProgressBar(false);
|
||||
mSuggestionsController.loadSuggestions(mLastVideo);
|
||||
bgImageUrl = mLastVideo.getBackgroundUrl();
|
||||
mSuggestionsController.loadSuggestions(getVideo());
|
||||
bgImageUrl = getVideo().getBackgroundUrl();
|
||||
|
||||
if (formatInfo.isHistoryBroken()) { // bot check error or the video is hidden
|
||||
YouTubeServiceManager.instance().applyNoPlaybackFix();
|
||||
@@ -391,8 +393,8 @@ public class VideoLoaderController extends BasePlayerController implements OnDat
|
||||
Log.d(TAG, "Empty format info received. Seems future live translation. No video data to pass to the player.");
|
||||
getPlayer().setTitle(formatInfo.getPlayabilityStatus());
|
||||
getPlayer().showProgressBar(false);
|
||||
mSuggestionsController.loadSuggestions(mLastVideo);
|
||||
bgImageUrl = mLastVideo.getBackgroundUrl();
|
||||
mSuggestionsController.loadSuggestions(getVideo());
|
||||
bgImageUrl = getVideo().getBackgroundUrl();
|
||||
scheduleReloadVideoTimer(30 * 1_000);
|
||||
}
|
||||
|
||||
@@ -539,7 +541,7 @@ public class VideoLoaderController extends BasePlayerController implements OnDat
|
||||
getPlayerData().setVideoBufferType(PlayerData.BUFFER_MEDIUM);
|
||||
}
|
||||
} else if (Helpers.containsAny(message, "Exception in CronetUrlRequest")) {
|
||||
if (mLastVideo != null && !mLastVideo.isLive) { // Finished live stream may provoke errors in Cronet
|
||||
if (getVideo() != null && !getVideo().isLive) { // Finished live stream may provoke errors in Cronet
|
||||
getPlayerTweaksData().setPlayerDataSource(PlayerTweaksData.PLAYER_DATA_SOURCE_DEFAULT);
|
||||
} else {
|
||||
restartEngine = false;
|
||||
@@ -565,8 +567,8 @@ public class VideoLoaderController extends BasePlayerController implements OnDat
|
||||
restartEngine = false;
|
||||
} else if (type == PlayerEventListener.ERROR_TYPE_RENDERER && rendererIndex == PlayerEventListener.RENDERER_INDEX_SUBTITLE) {
|
||||
// "Response code: 500"
|
||||
if (mLastVideo != null) {
|
||||
getPlayerData().disableSubtitlesPerChannel(mLastVideo.channelId);
|
||||
if (getVideo() != null) {
|
||||
getPlayerData().disableSubtitlesPerChannel(getVideo().channelId);
|
||||
getPlayerData().setFormat(getPlayerData().getDefaultSubtitleFormat());
|
||||
}
|
||||
restartEngine = false; // ???
|
||||
@@ -823,32 +825,32 @@ public class VideoLoaderController extends BasePlayerController implements OnDat
|
||||
private void loadRandomNext() {
|
||||
MediaServiceManager.instance().disposeActions();
|
||||
|
||||
if (getPlayer() == null || getPlayerData() == null || mLastVideo == null || mLastVideo.playlistInfo == null) {
|
||||
if (getPlayer() == null || getPlayerData() == null || getVideo() == null || getVideo().playlistInfo == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getPlayerData().getPlaybackMode() == PlayerConstants.PLAYBACK_MODE_SHUFFLE) {
|
||||
Video video = new Video();
|
||||
video.playlistId = mLastVideo.playlistId;
|
||||
video.playlistId = getVideo().playlistId;
|
||||
VideoGroup topRow = getPlayer().getSuggestionsByIndex(0);
|
||||
video.playlistIndex = mRandom.getPlaylistIndex(mLastVideo.getPlaylistId(),
|
||||
mLastVideo.playlistInfo.getSize() != -1 ? mLastVideo.playlistInfo.getSize() : topRow != null ? topRow.getVideos().size() : -1);
|
||||
video.playlistIndex = mRandom.getPlaylistIndex(getVideo().getPlaylistId(),
|
||||
getVideo().playlistInfo.getSize() != -1 ? getVideo().playlistInfo.getSize() : topRow != null ? topRow.getVideos().size() : -1);
|
||||
|
||||
MediaServiceManager.instance().loadMetadata(video, randomMetadata -> {
|
||||
if (randomMetadata.getNextVideo() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mLastVideo.nextMediaItemBackup == null) {
|
||||
mLastVideo.nextMediaItemBackup = mLastVideo.nextMediaItem;
|
||||
if (getVideo().nextMediaItemBackup == null) {
|
||||
getVideo().nextMediaItemBackup = getVideo().nextMediaItem;
|
||||
}
|
||||
|
||||
mLastVideo.nextMediaItem = SampleMediaItem.from(randomMetadata);
|
||||
getPlayer().setNextTitle(Video.from(mLastVideo.nextMediaItem));
|
||||
getVideo().nextMediaItem = SampleMediaItem.from(randomMetadata);
|
||||
getPlayer().setNextTitle(Video.from(getVideo().nextMediaItem));
|
||||
});
|
||||
} else if (mLastVideo.nextMediaItemBackup != null) {
|
||||
mLastVideo.nextMediaItem = mLastVideo.nextMediaItemBackup;
|
||||
getPlayer().setNextTitle(Video.from(mLastVideo.nextMediaItem));
|
||||
} else if (getVideo().nextMediaItemBackup != null) {
|
||||
getVideo().nextMediaItem = getVideo().nextMediaItemBackup;
|
||||
getPlayer().setNextTitle(Video.from(getVideo().nextMediaItem));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+13
-16
@@ -30,7 +30,6 @@ public class VideoStateController extends BasePlayerController {
|
||||
private static final long EMBED_THRESHOLD_MS = 30_000;
|
||||
private static final int HISTORY_UPDATE_INTERVAL_MINUTES = 5; // Sync history every five minutes
|
||||
private boolean mIsPlayEnabled;
|
||||
private Video mVideo = new Video();
|
||||
private boolean mIsPlayBlocked;
|
||||
private int mTickleLeft;
|
||||
private boolean mIncognito;
|
||||
@@ -44,7 +43,7 @@ public class VideoStateController extends BasePlayerController {
|
||||
@Override
|
||||
public void onNewVideo(Video item) {
|
||||
// Ensure that we aren't running on presenter init stage
|
||||
if (getPlayer() != null) {
|
||||
if (getPlayer() != null && getPlayer().containsMedia()) {
|
||||
if (!item.equals(getVideo())) { // a video might be opened twice (when remote connection enabled). Fix for that.
|
||||
// Reset auto-save history timer
|
||||
mTickleLeft = 0;
|
||||
@@ -52,8 +51,6 @@ public class VideoStateController extends BasePlayerController {
|
||||
// In case video opened from phone and other stuff.
|
||||
removeFromHistoryIfNeeded();
|
||||
saveState();
|
||||
} else if (isEmbedPlayer()) { // switching from embed to normal player
|
||||
savePosition();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,8 +130,12 @@ public class VideoStateController extends BasePlayerController {
|
||||
// Save previous state
|
||||
if (getPlayer().containsMedia()) {
|
||||
setPlayEnabled(getPlayer().getPlayWhenReady());
|
||||
saveState();
|
||||
persistState();
|
||||
if (isSwitchFromEmbed()) {
|
||||
savePosition();
|
||||
} else {
|
||||
saveState();
|
||||
persistState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +175,7 @@ public class VideoStateController extends BasePlayerController {
|
||||
@Override
|
||||
public void onVideoLoaded(Video item) {
|
||||
// Actual video that match currently loaded one.
|
||||
mVideo = item;
|
||||
//mVideo = item;
|
||||
|
||||
// Restore formats again.
|
||||
// Maybe this could help with Shield format problem.
|
||||
@@ -320,7 +321,8 @@ public class VideoStateController extends BasePlayerController {
|
||||
State state = getStateService().getByVideoId(item.videoId);
|
||||
|
||||
// Reset position of music videos
|
||||
boolean isShort = state != null && state.durationMs < MUSIC_VIDEO_MAX_DURATION_MS && !getPlayerTweaksData().isRememberPositionOfShortVideosEnabled();
|
||||
boolean isShort = state != null && state.durationMs < MUSIC_VIDEO_MAX_DURATION_MS
|
||||
&& !getPlayerTweaksData().isRememberPositionOfShortVideosEnabled() && !isSwitchFromEmbed();
|
||||
boolean isVideoEnded = state != null && state.durationMs - state.positionMs < 3_000;
|
||||
boolean isLive = item.isLive;
|
||||
|
||||
@@ -397,6 +399,8 @@ public class VideoStateController extends BasePlayerController {
|
||||
return;
|
||||
}
|
||||
|
||||
//Log.d(TAG, "Saving state of %s %s", getVideo().title, getPlayer().getPositionMs());
|
||||
|
||||
savePosition();
|
||||
updateHistory();
|
||||
syncWithPlaylists();
|
||||
@@ -421,7 +425,7 @@ public class VideoStateController extends BasePlayerController {
|
||||
getStateService().persistState();
|
||||
}
|
||||
|
||||
private void savePosition() {
|
||||
public void savePosition() {
|
||||
Video video = getVideo();
|
||||
|
||||
if (video == null || getPlayer() == null || !getPlayer().containsMedia()) {
|
||||
@@ -589,13 +593,6 @@ public class VideoStateController extends BasePlayerController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Actual video that match currently loaded one.
|
||||
*/
|
||||
private Video getVideo() {
|
||||
return mVideo;
|
||||
}
|
||||
|
||||
private boolean isMusicVideo() {
|
||||
Video item = getVideo();
|
||||
return item.belongsToMusic();
|
||||
|
||||
+37
-34
@@ -45,7 +45,9 @@ public class PlaybackPresenter extends BasePresenter<PlaybackView> implements Pl
|
||||
return super.add(listener);
|
||||
}
|
||||
};
|
||||
private WeakReference<Video> mVideo;
|
||||
private Video mPendingVideo;
|
||||
private boolean mIsSwitchFromEmbed;
|
||||
// Fix for using destroyed view
|
||||
private WeakReference<PlaybackView> mPlayer = new WeakReference<>(null);
|
||||
|
||||
@@ -96,18 +98,8 @@ public class PlaybackPresenter extends BasePresenter<PlaybackView> implements Pl
|
||||
return mPendingVideo != null;
|
||||
}
|
||||
|
||||
public void openVideo(Video video) {
|
||||
if (video == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getView() == null) {
|
||||
mPendingVideo = video;
|
||||
} else {
|
||||
onNewVideo(video);
|
||||
}
|
||||
|
||||
getViewManager().startView(PlaybackView.class);
|
||||
public void openVideo(String videoId) {
|
||||
openVideo(videoId, false, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,30 +116,33 @@ public class PlaybackPresenter extends BasePresenter<PlaybackView> implements Pl
|
||||
openVideo(video);
|
||||
}
|
||||
|
||||
public void openVideo(String videoId) {
|
||||
openVideo(videoId, false, -1);
|
||||
}
|
||||
|
||||
///**
|
||||
// * Opens video item from browser, search or channel views<br/>
|
||||
// * Also prepares and start the playback view.
|
||||
// */
|
||||
//public void openVideo(Video item) {
|
||||
// if (item == null) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// mMainController.openVideo(item);
|
||||
//
|
||||
// mViewManager.startView(PlaybackView.class);
|
||||
//}
|
||||
|
||||
public Video getVideo() {
|
||||
if (getView() == null) {
|
||||
return null;
|
||||
public void openVideo(Video video) {
|
||||
if (video == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
return getView().getVideo();
|
||||
if (getView() == null) {
|
||||
mPendingVideo = video;
|
||||
} else if (getView().isEmbed()) { // switching from the embed player to the fullscreen one
|
||||
mIsSwitchFromEmbed = true;
|
||||
// The embed player doesn't disposed properly
|
||||
// NOTE: don't release after init check because this depends on timings
|
||||
onEngineReleased();
|
||||
setView(null);
|
||||
onNewVideo(video);
|
||||
} else {
|
||||
onNewVideo(video);
|
||||
}
|
||||
|
||||
getViewManager().startView(PlaybackView.class);
|
||||
}
|
||||
|
||||
public Video getVideo() {
|
||||
return mVideo != null ? mVideo.get() : null;
|
||||
}
|
||||
|
||||
public boolean isSwitchFromEmbed() {
|
||||
return mIsSwitchFromEmbed;
|
||||
}
|
||||
|
||||
public boolean isRunningInBackground() {
|
||||
@@ -215,6 +210,11 @@ public class PlaybackPresenter extends BasePresenter<PlaybackView> implements Pl
|
||||
public void setView(PlaybackView view) {
|
||||
super.setView(view);
|
||||
mPlayer = new WeakReference<>(view);
|
||||
|
||||
if (view != null && view.getVideo() != null) {
|
||||
// Just in case switching between embed and fullscreen players
|
||||
mVideo = new WeakReference<>(view.getVideo());
|
||||
}
|
||||
}
|
||||
|
||||
public PlaybackView getPlayer() {
|
||||
@@ -241,6 +241,7 @@ public class PlaybackPresenter extends BasePresenter<PlaybackView> implements Pl
|
||||
@Override
|
||||
public void onNewVideo(Video video) {
|
||||
process(listener -> listener.onNewVideo(video));
|
||||
mVideo = new WeakReference<>(video);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -308,6 +309,8 @@ public class PlaybackPresenter extends BasePresenter<PlaybackView> implements Pl
|
||||
getTickleManager().addListener(this);
|
||||
|
||||
process(PlayerEventListener::onEngineInitialized);
|
||||
|
||||
mIsSwitchFromEmbed = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
@@ -1145,6 +1145,10 @@ public class PlaybackFragment extends SeekModePlaybackFragment implements Playba
|
||||
|
||||
@Override
|
||||
public Video getVideo() {
|
||||
if (mExoPlayerController == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return mExoPlayerController.getVideo();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user