everyone I am getting an issue in audio files that I have been trying to give them the path in javascript's dictionary for creating a music player. I already used 'src' and 'URL' before the file path but every time function did not work. I just want to know how I can give them the path that function can access and play songs that are inside the dictionary. Any help would be appreciated. I am a fresher and learning programming by myself. Thanks
Here is the complete code.......
enter code here
<script>
let pause_btn = document.querySelector('.playPause');
let backward_btn = document.querySelector('.playBack');
let next_btn = document.querySelector('.playNext');
let track_index = 0;
let curr_track = document.createElement('audio');
isPlaying = false;
let updateTimer;
let track_list =[{
path: url(../music/song.mp3)}///////HERE I AM GETTING AN ISSUE
]
function loadTrack(track_index){
clearInterval(updateTimer);
// resetValues();
//load a new track
curr_track.src = track_list[track_index].path;
curr_track.load();
//update time interval
updateTimer = setInterval(seekUpdate,1000);
//move to the next track if the current finishes playing using the 'ended' event
curr_track.addEventListener('ended',next_song)
}
function playTrack(){
curr_track.play();
isPlaying = true;
pause_btn.innerHTML = "<i class= 'fa fa-pause-circle fa-5x'></i>";
}
function pauseTrack(){
curr_track.pause();
isPlaying =false;
pause_btn.innerHTML = "<i class= 'fa fa-play-circle fa-5x'></i>";
}
function play_pause_track(){
if(!isPlaying)playTrack();
else pauseTrack();
}
function previous_song(){
if(track_index>0){
track_index -=1;
}else{
track_index = track_list.length-1;
}
curr_track.load();
playTrack();
}
function next_song(){
if(track_index<track_list.length-1){
track_index+=1;
}else{
track_index =0;
}
curr_track.load();
playTrack();
}
</script>
First sure that your URL is correct and then try:
let track_list =[{
path: "../music/song.mp3"}
]