more aggressive shuffling

This commit is contained in:
vapormusic 2022-01-08 10:39:18 +07:00
parent 1abd9150cb
commit afc0575ba7

View file

@ -2260,6 +2260,16 @@ const app = new Vue({
} }
}, },
queueParentandplayChild(parent, childIndex, item) { queueParentandplayChild(parent, childIndex, item) {
/* Randomize array in-place using Durstenfeld shuffle algorithm */
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
let kind = parent.substring(0, parent.indexOf(":")) let kind = parent.substring(0, parent.indexOf(":"))
let id = parent.substring(parent.indexOf(":") + 1, parent.length) let id = parent.substring(parent.indexOf(":") + 1, parent.length)
let truekind = (!kind.endsWith("s")) ? (kind + "s") : kind; let truekind = (!kind.endsWith("s")) ? (kind + "s") : kind;
@ -2278,6 +2288,7 @@ const app = new Vue({
} catch (e) { } catch (e) {
} }
this.mk.clearQueue().then(function (_) { this.mk.clearQueue().then(function (_) {
if (app.mk.shuffleMode == 1){ shuffleArray(query)}
app.mk.queue.append(query) app.mk.queue.append(query)
if (childIndex != -1) { if (childIndex != -1) {
app.mk.changeToMediaAtIndex(childIndex) app.mk.changeToMediaAtIndex(childIndex)
@ -2302,10 +2313,12 @@ const app = new Vue({
app.mk.clearQueue().then(function () { app.mk.clearQueue().then(function () {
if ((app.showingPlaylist && app.showingPlaylist.id == id)) { if ((app.showingPlaylist && app.showingPlaylist.id == id)) {
let query = app.showingPlaylist.relationships.tracks.data.map(item => new MusicKit.MediaItem(item)); let query = app.showingPlaylist.relationships.tracks.data.map(item => new MusicKit.MediaItem(item));
if (app.mk.shuffleMode == 1){ shuffleArray(query)}
app.mk.queue.append(query) app.mk.queue.append(query)
} else { } else {
app.getPlaylistFromID(id, true).then(function () { app.getPlaylistFromID(id, true).then(function () {
let query = app.showingPlaylist.relationships.tracks.data.map(item => new MusicKit.MediaItem(item)); let query = app.showingPlaylist.relationships.tracks.data.map(item => new MusicKit.MediaItem(item));
if (app.mk.shuffleMode == 1){ shuffleArray(query)}
app.mk.queue.append(query) app.mk.queue.append(query)
}) })
} }