mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-23 12:09:30 -07:00
playlist implementation
This commit is contained in:
@@ -120,17 +120,12 @@ const initializePlayer = () => {
|
|||||||
player.addEventListener('canplay', playerCanPlay);
|
player.addEventListener('canplay', playerCanPlay);
|
||||||
player.addEventListener('ended', playerEnded);
|
player.addEventListener('ended', playerEnded);
|
||||||
|
|
||||||
// add the tracks
|
// get the first file
|
||||||
const tracks = playlist.availableFiles.map((file) => {
|
player.src = `music/${playlist.availableFiles[currentTrack]}`;
|
||||||
const elem = document.createElement('source');
|
player.type = 'audio/mpeg';
|
||||||
elem.src = `music/${file}`;
|
|
||||||
elem.type = 'audio/mpeg';
|
|
||||||
return elem;
|
|
||||||
});
|
|
||||||
|
|
||||||
// add the track to the player
|
// reload the player
|
||||||
player.append(...tracks);
|
console.log('player initialized');
|
||||||
console.log('tracks added');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const playerCanPlay = () => {
|
const playerCanPlay = () => {
|
||||||
@@ -141,7 +136,15 @@ const playerCanPlay = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const playerEnded = () => {
|
const playerEnded = () => {
|
||||||
console.log('end of playlist reached');
|
// next track
|
||||||
|
currentTrack += 1;
|
||||||
|
// roll over and re-randomize the tracks
|
||||||
|
if (currentTrack >= playlist.availableFiles) {
|
||||||
|
randomizePlaylist();
|
||||||
|
currentTrack = 0;
|
||||||
|
}
|
||||||
|
// update the player source
|
||||||
|
player.src = `music/${playlist.availableFiles[currentTrack]}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|||||||
Reference in New Issue
Block a user