Remove thumbnail before sync, if outdated
Also refactor onPlaybackSynchronize and add comments
This commit is contained in:
parent
7fbef35daa
commit
4a7af6f9ac
|
@ -1509,48 +1509,50 @@ public final class Player implements PlaybackListener, Listener {
|
||||||
Log.d(TAG, "Playback - onPlaybackSynchronize(was blocked: " + wasBlocked
|
Log.d(TAG, "Playback - onPlaybackSynchronize(was blocked: " + wasBlocked
|
||||||
+ ") called with item=[" + item.getTitle() + "], url=[" + item.getUrl() + "]");
|
+ ") called with item=[" + item.getTitle() + "], url=[" + item.getUrl() + "]");
|
||||||
}
|
}
|
||||||
if (exoPlayerIsNull() || playQueue == null) {
|
if (exoPlayerIsNull() || playQueue == null || currentItem == item) {
|
||||||
return;
|
return; // nothing to synchronize
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean hasPlayQueueItemChanged = currentItem != item;
|
final int playQueueIndex = playQueue.indexOf(item);
|
||||||
|
final int playlistIndex = simpleExoPlayer.getCurrentMediaItemIndex();
|
||||||
|
final int playlistSize = simpleExoPlayer.getCurrentTimeline().getWindowCount();
|
||||||
|
final boolean removeThumbnailBeforeSync = currentItem == null
|
||||||
|
|| currentItem.getServiceId() != item.getServiceId()
|
||||||
|
|| !currentItem.getUrl().equals(item.getUrl());
|
||||||
|
|
||||||
final int currentPlayQueueIndex = playQueue.indexOf(item);
|
|
||||||
final int currentPlaylistIndex = simpleExoPlayer.getCurrentMediaItemIndex();
|
|
||||||
final int currentPlaylistSize = simpleExoPlayer.getCurrentTimeline().getWindowCount();
|
|
||||||
|
|
||||||
// If nothing to synchronize
|
|
||||||
if (!hasPlayQueueItemChanged) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
currentItem = item;
|
currentItem = item;
|
||||||
|
|
||||||
// Check if on wrong window
|
if (playQueueIndex != playQueue.getIndex()) {
|
||||||
if (currentPlayQueueIndex != playQueue.getIndex()) {
|
// wrong window (this should be impossible, as this method is called with
|
||||||
Log.e(TAG, "Playback - Play Queue may be desynchronized: item "
|
// `item=playQueue.getItem()`, so the index of that item must be equal to `getIndex()`)
|
||||||
+ "index=[" + currentPlayQueueIndex + "], "
|
Log.e(TAG, "Playback - Play Queue may be not in sync: item index=["
|
||||||
+ "queue index=[" + playQueue.getIndex() + "]");
|
+ playQueueIndex + "], " + "queue index=[" + playQueue.getIndex() + "]");
|
||||||
|
|
||||||
// Check if bad seek position
|
} else if ((playlistSize > 0 && playQueueIndex >= playlistSize) || playQueueIndex < 0) {
|
||||||
} else if ((currentPlaylistSize > 0 && currentPlayQueueIndex >= currentPlaylistSize)
|
// the queue and the player's timeline are not in sync, since the play queue index
|
||||||
|| currentPlayQueueIndex < 0) {
|
// points outside of the timeline
|
||||||
Log.e(TAG, "Playback - Trying to seek to invalid "
|
Log.e(TAG, "Playback - Trying to seek to invalid index=[" + playQueueIndex
|
||||||
+ "index=[" + currentPlayQueueIndex + "] with "
|
+ "] with playlist length=[" + playlistSize + "]");
|
||||||
+ "playlist length=[" + currentPlaylistSize + "]");
|
|
||||||
|
|
||||||
} else if (wasBlocked || currentPlaylistIndex != currentPlayQueueIndex || !isPlaying()) {
|
} else if (wasBlocked || playlistIndex != playQueueIndex || !isPlaying()) {
|
||||||
|
// either the player needs to be unblocked, or the play queue index has just been
|
||||||
|
// changed and needs to be synchronized, or the player is not playing
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "Playback - Rewinding to correct "
|
Log.d(TAG, "Playback - Rewinding to correct index=[" + playQueueIndex + "], "
|
||||||
+ "index=[" + currentPlayQueueIndex + "], "
|
+ "from=[" + playlistIndex + "], size=[" + playlistSize + "].");
|
||||||
+ "from=[" + currentPlaylistIndex + "], "
|
|
||||||
+ "size=[" + currentPlaylistSize + "].");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (removeThumbnailBeforeSync) {
|
||||||
|
// unset the current (now outdated) thumbnail to ensure it is not used during sync
|
||||||
|
onThumbnailLoaded(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// sync the player index with the queue index, and seek to the correct position
|
||||||
if (item.getRecoveryPosition() != PlayQueueItem.RECOVERY_UNSET) {
|
if (item.getRecoveryPosition() != PlayQueueItem.RECOVERY_UNSET) {
|
||||||
simpleExoPlayer.seekTo(currentPlayQueueIndex, item.getRecoveryPosition());
|
simpleExoPlayer.seekTo(playQueueIndex, item.getRecoveryPosition());
|
||||||
playQueue.unsetRecovery(currentPlayQueueIndex);
|
playQueue.unsetRecovery(playQueueIndex);
|
||||||
} else {
|
} else {
|
||||||
simpleExoPlayer.seekToDefaultPosition(currentPlayQueueIndex);
|
simpleExoPlayer.seekToDefaultPosition(playQueueIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue