Skip to content

[pull] master from yuliskov:master #627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,4 @@ protected PlaybackPresenter getPlaybackPresenter() {
protected boolean isEmbedPlayer() {
return getPlayer() != null && getPlayer().isEmbed();
}

protected boolean isSwitchFromEmbed() {
return mMainController != null && mMainController.isSwitchFromEmbed();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private void disposeActions() {
}

private void skipSegment(long interval) {
if (mActiveSegments == null || mActiveSegments.isEmpty() || !Helpers.equals(mVideoId, getVideo())) {
if (mActiveSegments == null || mActiveSegments.isEmpty() || getVideo() == null || !Helpers.equals(mVideoId, getVideo().videoId)) {
disposeActions();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void onEngineInitialized() {
return;
}

loadVideo(Helpers.firstNonNull(mPendingVideo, getPlayer().getVideo(), getVideo()));
loadVideo(Helpers.firstNonNull(mPendingVideo, getVideo()));
getPlayer().setButtonState(R.id.action_repeat, getPlayerData().getPlaybackMode());
mSleepTimerStartMs = System.currentTimeMillis();
mPendingVideo = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ public void onNewVideo(Video item) {

enableIncognitoIfNeeded(item);

// Don't do reset on videoLoaded state because this will influences minimized music videos.
resetPositionIfNeeded(item);
resetGlobalSpeedIfNeeded();
if (!item.equals(getVideo())) { // skip switch from the embed to the fullscreen one
// Don't do reset on videoLoaded state because this will influences minimized music videos.
resetPositionIfNeeded(item);
resetGlobalSpeedIfNeeded();
}
}

@Override
Expand Down Expand Up @@ -130,12 +132,8 @@ public void onEngineReleased() {
// Save previous state
if (getPlayer().containsMedia()) {
setPlayEnabled(getPlayer().getPlayWhenReady());
if (isSwitchFromEmbed()) {
savePosition();
} else {
saveState();
persistState();
}
saveState();
persistState();
}
}

Expand Down Expand Up @@ -322,7 +320,7 @@ private void resetPositionIfNeeded(Video item) {

// Reset position of music videos
boolean isShort = state != null && state.durationMs < MUSIC_VIDEO_MAX_DURATION_MS
&& !getPlayerTweaksData().isRememberPositionOfShortVideosEnabled() && !isSwitchFromEmbed();
&& !getPlayerTweaksData().isRememberPositionOfShortVideosEnabled();
boolean isVideoEnded = state != null && state.durationMs - state.positionMs < 3_000;
boolean isLive = item.isLive;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public boolean add(PlayerEventListener listener) {
};
private WeakReference<Video> mVideo;
private Video mPendingVideo;
private boolean mIsSwitchFromEmbed;
// Fix for using destroyed view
private WeakReference<PlaybackView> mPlayer = new WeakReference<>(null);

Expand Down Expand Up @@ -124,10 +123,10 @@ public void openVideo(Video video) {
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();
//onEngineReleased();
getController(VideoStateController.class).savePosition();
setView(null);
onNewVideo(video);
} else {
Expand All @@ -141,10 +140,6 @@ public Video getVideo() {
return mVideo != null ? mVideo.get() : null;
}

public boolean isSwitchFromEmbed() {
return mIsSwitchFromEmbed;
}

public boolean isRunningInBackground() {
return getView() != null &&
getView().isEngineBlocked() &&
Expand Down Expand Up @@ -309,8 +304,6 @@ public void onEngineInitialized() {
getTickleManager().addListener(this);

process(PlayerEventListener::onEngineInitialized);

mIsSwitchFromEmbed = false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ private int findPositionById(int id) {
Object row = getResultsAdapter().get(i);

if (row instanceof ListRow) {
VideoGroupObjectAdapter adapter = (VideoGroupObjectAdapter) ((ListRow) row).getAdapter();
// Could be one of those: TagAdapter, VideoGroupObjectAdapter
ObjectAdapter adapter = ((ListRow) row).getAdapter();
if (adapter == needed) {
return i;
}
Expand Down