1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Add playlist shuffling toggle to remotecontrol.js

This commit is contained in:
ferferga 2020-06-18 01:19:59 +02:00
parent 74d32d3cbd
commit ff6bfbf2b4
12 changed files with 143 additions and 7 deletions

View file

@ -24,8 +24,10 @@ define([], function () {
function PlayQueueManager() {
this._sortedPlaylist = [];
this._playlist = [];
this._repeatMode = 'RepeatNone';
this._shuffleMode = 'Sorted';
}
PlayQueueManager.prototype.getPlaylist = function () {
@ -56,6 +58,30 @@ define([], function () {
}
};
PlayQueueManager.prototype.shufflePlaylist = function () {
this._sortedPlaylist = [];
for (let item of this._playlist) {
this._sortedPlaylist.push(item);
}
for (let i = this._playlist.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * i);
const temp = this._playlist[i];
this._playlist[i] = this._playlist[j];
this._playlist[j] = temp;
}
this._shuffleMode = 'Shuffle';
};
PlayQueueManager.prototype.sortShuffledPlaylist = function () {
this._playlist = [];
for (let item of this._sortedPlaylist) {
this._playlist.push(item);
}
this._sortedPlaylist = [];
this._shuffleMode = 'Sorted';
};
function arrayInsertAt(destArray, pos, arrayToInsert) {
var args = [];
args.push(pos); // where to insert
@ -176,21 +202,39 @@ define([], function () {
PlayQueueManager.prototype.reset = function () {
this._sortedPlaylist = [];
this._playlist = [];
this._currentPlaylistItemId = null;
this._repeatMode = 'RepeatNone';
this._shuffleMode = 'Sorted';
};
PlayQueueManager.prototype.setRepeatMode = function (value) {
this._repeatMode = value;
if (value === 'RepeatOne' || value === 'RepeatAll' || value === 'RepeatNone') {
this._repeatMode = value;
} else {
throw new TypeError('invalid value provided for setRepeatMode');
}
};
PlayQueueManager.prototype.getRepeatMode = function () {
return this._repeatMode;
};
PlayQueueManager.prototype.setShuffleMode = function (value) {
if (value === 'Sorted') {
this.sortShuffledPlaylist();
} else if (value === 'Shuffle') {
this.shufflePlaylist();
} else {
throw new TypeError('invalid value provided for setShuffleMode');
}
};
PlayQueueManager.prototype.getShuffleMode = function () {
return this._shuffleMode;
};
PlayQueueManager.prototype.getNextItemInfo = function () {
var newIndex;