I have a problem with a tracklist created from a folder like that:
let tracks = [];
let art_str = [];
let name_str = [];
const traxFolder = './Resto';
const fst = require('fs');
fst.readdirSync(traxFolder).forEach(track => {
tracks.push(track);
name_str.push(track.substring(track.indexOf("-") + 1 ,track.indexOf(".")));
art_str.push(track.substring(0, track.indexOf("-")));
});
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
let j = Math.floor(Math.random() * (i + 1));
let temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
let track_list = tracks.map ((sng,i) => ({path : `${traxFolder}/${sng}` ,
name:name_str[i],
artist: art_str[i],
image: "https://images.pexels.com/photos/1717969/pexels-photo-1717969.jpeg?
auto=compress&cs=tinysrgb&dpr=3&h=250&w=250"}));
//shuffleArray(track_list);
console.log(track_list);
the above code creates an array track_list and i can see all the objects are ok in the console! when i use this function:
let track_index = 0;
let isPlaying = false;
let updateTimer;
let curr_track = document.createElement('audio');
function loadTrack(list_index) {
clearInterval(updateTimer);
resetValues();
curr_track.src = track_list[list_index].path;
curr_track.load();
}
loadTrack(track_index);
it doesnt load the track of index zero or any track_index i try 1,2,3 etc. while the same exact code workd perfect if the array track_list comes in this form:
let track_list = [
{
name: "Clear As Water",
artist: "Una Mas Trio",
image: "https://images.pexels.com/photos/2264753/pexels-photo-2264753etcetc
path: "resto/Una Mas Trio - Clear As Water (Hidden Jazz Quartet Remix).mp3"
},
{
name: "Mango Woman",
artist: "Mo Horizons",
image: "https://images.pexels.com/photos/3100835/pexels-photo-etcetc
path: "musiclists/Mo Horizons - Mango Woman.mp3"
},
{
name: "Invitation To Dance (Vincemo Hang Sessions Mix)",
artist: "Monotone",
image: "https://images.pexels.com/photos/1717969/pexels-etc etc
path: "musiclists/Monotone-Invitation To Dance (Vincemo Hang Sessions Mix).mp3",
},
];
Can anyone tell me why the first array does not seem to load any track while the second does when the only difference IN THE CODE is the way the array track_list is created , WHILE THE OBJECT PROPERTIES ARE IDENTICAL?
Thanks and Regards to everyone
resetValues()function does?_in your audio files to avoid potential path problems