playlist trim fix

This commit is contained in:
Yuriy Liskov
2020-09-30 21:23:46 +03:00
parent b5795b1127
commit 8266b36971
2 changed files with 6 additions and 10 deletions
@@ -33,12 +33,6 @@ public class Playlist {
mCurrentPosition = -1;
}
public void clearNext() {
if (mCurrentPosition > 0 && (mCurrentPosition + 1) < mPlaylist.size()) {
mPlaylist = mPlaylist.subList(mCurrentPosition + 1, mPlaylist.size());
}
}
/**
* Adds a video to the end of the playlist.
*
@@ -49,10 +43,14 @@ public class Playlist {
mPlaylist.set(mCurrentPosition, video);
} else {
mPlaylist.add(++mCurrentPosition, video);
trimPlaylist();
}
trimPlaylist();
}
/**
* Trim playlist if one exceeds needed size or current element not last in the list
*/
private void trimPlaylist() {
int fromIndex = 0;
int toIndex = mCurrentPosition + 1;
@@ -66,6 +64,7 @@ public class Playlist {
if (!isLastElement || playlistTooBig) {
mPlaylist = mPlaylist.subList(fromIndex, toIndex);
mCurrentPosition = mPlaylist.size() - 1;
}
}
@@ -35,9 +35,6 @@ public class VideoLoader extends PlayerEventListenerHelper implements MetadataLi
public void openVideo(Video item) {
mPlaylist.add(item);
// reset next video prediction when new video opens
mPlaylist.clearNext();
if (mEngineInitialized) { // player is initialized
if (!item.equals(mLastVideo)) {
loadVideo(item); // play immediately