intends to design a player, in which a function controls that a song can be played by clicking on the menu. Calling music.play () in this function and continuing to console.log (music.src) can display the src path normally.
however, in another function that controls the playback of the next song, both the output src and currentSrc are displayed undefined, and even related properties such as the output currentTime are displayed as 0. The related code is as follows:
function prevSong(msc){ //
let s = msc.currentSrc;
let tar;
/*
tar,
*/
msc.pause();
if(tar.previousSibling.nodeName == "LI"){
let index = tar.previousSibling.innerHTML;
msc.src = "src/music/"+index+".mp3";
}else{
let chd = tar.parentNode.childNodes;
let res = chd[chd.length-1];
msc.src = "src/music/"+res.innerHTML+".mp3"
}
//msc.load();
msc.play();
}
in addition, how to get the audio length duration? normally According to all kinds of online solutions, I use onloadedmetadata or even promise, to output NaN
. send demo directly to post: http://www.malakh.xyz/demo2/
js: http://www.malakh.xyz/demo2/s.