mirror of
https://github.com/yuliskov/SmartTube.git
synced 2026-01-27 09:00:45 -06:00
state restore fix
This commit is contained in:
@@ -21,18 +21,9 @@ public final class Video implements Parcelable {
|
||||
public String videoUrl;
|
||||
public String studio;
|
||||
public int percentWatched;
|
||||
public State state;
|
||||
public MediaItem mediaItem;
|
||||
public MediaItemMetadata cachedMetadata;
|
||||
|
||||
public static class State {
|
||||
public final long positionMs;
|
||||
|
||||
public State(long positionMs) {
|
||||
this.positionMs = positionMs;
|
||||
}
|
||||
}
|
||||
|
||||
public Video() {
|
||||
|
||||
}
|
||||
|
||||
@@ -2,15 +2,28 @@ package com.liskovsoft.smartyoutubetv2.common.app.models.playback.managers;
|
||||
|
||||
import com.liskovsoft.sharedutils.helpers.Helpers;
|
||||
import com.liskovsoft.smartyoutubetv2.common.app.models.data.Video;
|
||||
import com.liskovsoft.smartyoutubetv2.common.app.models.data.Video.State;
|
||||
import com.liskovsoft.smartyoutubetv2.common.app.models.playback.PlayerEventListenerHelper;
|
||||
import com.liskovsoft.smartyoutubetv2.common.autoframerate.FormatItem;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class StateUpdater extends PlayerEventListenerHelper {
|
||||
private boolean mIsPlaying;
|
||||
private int mRepeatMode = 0;
|
||||
private FormatItem mVideoFormat = FormatItem.HD_AVC;
|
||||
private static final long MUSIC_VIDEO_LENGTH_MS = 6 * 60 * 1000;
|
||||
// Don't store state inside Video object.
|
||||
// As one video might correspond to multiple Video objects.
|
||||
private final Map<String, State> mStates = new HashMap<>();
|
||||
|
||||
private static class State {
|
||||
public final long positionMs;
|
||||
|
||||
public State(long positionMs) {
|
||||
this.positionMs = positionMs;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openVideo(Video item) {
|
||||
@@ -86,26 +99,35 @@ public class StateUpdater extends PlayerEventListenerHelper {
|
||||
}
|
||||
|
||||
private void saveState() {
|
||||
trimStorage();
|
||||
|
||||
Video video = mController.getVideo();
|
||||
|
||||
if (video != null) {
|
||||
video.state = new State(mController.getPositionMs());
|
||||
mStates.put(video.videoId, new State(mController.getPositionMs()));
|
||||
}
|
||||
}
|
||||
|
||||
private void trimStorage() {
|
||||
// NOP
|
||||
}
|
||||
|
||||
private void restoreState(Video item) {
|
||||
if (mVideoFormat != null) {
|
||||
mController.selectFormat(mVideoFormat);
|
||||
}
|
||||
|
||||
if (item.state == null && item.percentWatched > 0 && item.percentWatched < 100) {
|
||||
item.state = new State(getNewPosition(item.percentWatched));
|
||||
State state = mStates.get(item.videoId);
|
||||
|
||||
// internal storage has priority over item data loaded from network
|
||||
if (state == null && item.percentWatched > 0 && item.percentWatched < 100) {
|
||||
state = new State(getNewPosition(item.percentWatched));
|
||||
}
|
||||
|
||||
boolean nearEnd = Math.abs(mController.getLengthMs() - mController.getPositionMs()) < 10_000;
|
||||
|
||||
if (item.state != null && !nearEnd) {
|
||||
mController.setPositionMs(item.state.positionMs);
|
||||
if (state != null && !nearEnd) {
|
||||
mController.setPositionMs(state.positionMs);
|
||||
mController.setPlay(mIsPlaying);
|
||||
} else {
|
||||
mController.setPlay(true); // start play immediately when state not found
|
||||
|
||||
@@ -63,7 +63,7 @@ public class PlaybackPresenter implements Presenter<PlaybackView> {
|
||||
}
|
||||
|
||||
private void focusView() {
|
||||
if (mView != null && mView.getController().isPIPEnabled()) {
|
||||
if (mView != null && mView.getController().isEngineBlocked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user