mirror of
https://github.com/yuliskov/SmartTube.git
synced 2026-02-05 14:25:40 -06:00
player: shuffle fixes
This commit is contained in:
Submodule MediaServiceCore updated: 0760a99982...1b3e3cb3fd
@@ -822,34 +822,18 @@ public class VideoLoaderController extends BasePlayerController {
|
||||
}
|
||||
|
||||
if (getPlayerData().getPlaybackMode() == PlayerConstants.PLAYBACK_MODE_SHUFFLE) {
|
||||
VideoGroup topRow = getPlayer().getSuggestionsByIndex(0);
|
||||
Video video = new Video();
|
||||
video.playlistId = getVideo().playlistId;
|
||||
video.playlistIndex = UniqueRandom.getRandomIndex(getVideo().playlistInfo.getCurrentIndex(), getVideo().playlistInfo.getSize());
|
||||
|
||||
if (topRow != null) {
|
||||
int currentIdx = topRow.indexOf(getVideo());
|
||||
int randomIndex = UniqueRandom.getRandomIndex(currentIdx, topRow.getSize());
|
||||
|
||||
if (randomIndex != -1) {
|
||||
Video nextVideo = topRow.get(randomIndex);
|
||||
getVideo().nextMediaItem = SimpleMediaItem.from(nextVideo);
|
||||
getPlayer().setNextTitle(nextVideo);
|
||||
MediaServiceManager.instance().loadMetadata(video, randomMetadata -> {
|
||||
if (randomMetadata.getNextVideo() == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//Video video = new Video();
|
||||
//video.playlistId = getVideo().playlistId;
|
||||
//VideoGroup topRow = getPlayer().getSuggestionsByIndex(0);
|
||||
//
|
||||
//video.playlistIndex = UniqueRandom.getRandomIndex(getVideo().getPositionInsideGroup(),
|
||||
// getVideo().playlistInfo.getSize() != -1 ? getVideo().playlistInfo.getSize() : topRow != null ? topRow.getVideos().size() : -1);
|
||||
//
|
||||
//MediaServiceManager.instance().loadMetadata(video, randomMetadata -> {
|
||||
// if (randomMetadata.getNextVideo() == null) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// getVideo().nextMediaItem = SimpleMediaItem.from(randomMetadata);
|
||||
// getPlayer().setNextTitle(Video.from(getVideo().nextMediaItem));
|
||||
//});
|
||||
getVideo().nextMediaItem = SimpleMediaItem.from(randomMetadata);
|
||||
getPlayer().setNextTitle(Video.from(getVideo().nextMediaItem));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,37 @@ import com.liskovsoft.sharedutils.helpers.Helpers;
|
||||
|
||||
public class UniqueRandom {
|
||||
private static final int RANDOM_FAIL_REPEAT_TIMES = 10;
|
||||
//private List<Integer> mUsedIndexes;
|
||||
//private int mPlaylistSize;
|
||||
//private String mPlaylistId;
|
||||
|
||||
//public int getPlaylistIndex(int playlistSize) {
|
||||
// return getPlaylistIndex(null, playlistSize);
|
||||
//}
|
||||
//
|
||||
//public int getPlaylistIndex(String playlistId, int playlistSize) {
|
||||
// if (mUsedIndexes == null) {
|
||||
// mUsedIndexes = new ArrayList<>();
|
||||
// }
|
||||
//
|
||||
// if (!Helpers.equals(mPlaylistId, playlistId) || mPlaylistSize != playlistSize || mUsedIndexes.size() == playlistSize) {
|
||||
// mUsedIndexes.clear();
|
||||
// mPlaylistSize = playlistSize;
|
||||
// mPlaylistId = playlistId;
|
||||
// }
|
||||
//
|
||||
// int randomIndex = 0;
|
||||
//
|
||||
// for (int i = 0; i < RANDOM_FAIL_REPEAT_TIMES; i++) {
|
||||
// randomIndex = Helpers.getRandomIndex(playlistSize);
|
||||
// if (!mUsedIndexes.contains(randomIndex)) {
|
||||
// mUsedIndexes.add(randomIndex);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return randomIndex;
|
||||
//}
|
||||
|
||||
public static int getRandomIndex(int currentIdx, int playlistSize) {
|
||||
if (playlistSize <= 1) {
|
||||
|
||||
Reference in New Issue
Block a user