mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-22 19:49:31 -07:00
playlist randomized
This commit is contained in:
@@ -29,6 +29,8 @@ const getMedia = async () => {
|
|||||||
const enableMediaPlayer = () => {
|
const enableMediaPlayer = () => {
|
||||||
// see if files are available
|
// see if files are available
|
||||||
if (playlist?.availableFiles?.length > 0) {
|
if (playlist?.availableFiles?.length > 0) {
|
||||||
|
// randomize the list
|
||||||
|
randomizePlaylist();
|
||||||
// enable the icon
|
// enable the icon
|
||||||
const icon = document.getElementById('ToggleMedia');
|
const icon = document.getElementById('ToggleMedia');
|
||||||
icon.classList.add('available');
|
icon.classList.add('available');
|
||||||
@@ -78,6 +80,20 @@ const stateChanged = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const randomizePlaylist = () => {
|
||||||
|
let availableFiles = [...playlist.availableFiles];
|
||||||
|
const randomPlaylist = [];
|
||||||
|
while (availableFiles.length > 0) {
|
||||||
|
// get a randon item from the available files
|
||||||
|
const i = Math.floor(Math.random() * availableFiles.length);
|
||||||
|
// add it to the final list
|
||||||
|
randomPlaylist.push(availableFiles[i]);
|
||||||
|
// remove the file from the available files
|
||||||
|
availableFiles = availableFiles.filter((file, index) => index !== i);
|
||||||
|
}
|
||||||
|
playlist.availableFiles = randomPlaylist;
|
||||||
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
// eslint-disable-next-line import/prefer-default-export
|
// eslint-disable-next-line import/prefer-default-export
|
||||||
toggleMedia,
|
toggleMedia,
|
||||||
|
|||||||
Reference in New Issue
Block a user