Home Article Practice 音乐播放器

音乐播放器

2022-04-23 13:24  views:420  source:1314520    

<script type="text/javascript" src="js/0 .js"></script>
var audio=document.createElement('audio');
console.log(audio);
audio.src = "music/ .mp3"
var objSpNum = document.getElementById("sp_num");
console.log(objSpNum);
// var currentNum = objSpNum.innerText; //表单标签
var currentNum=1;
console.log(currentNum);
window.onload = function() {
var objBtnPlay = document.getElementById("play");
var objBtnPause = document.getElementById("pause");
var objBtnPrev = document.getElementById("prev");
var objBtnNext = document.getElementById("next");
objBtnPlay.onclick = playMusic;
objBtnPause.onclick = pauseMusic;
objBtnPrev.onclick = prevMusic;
objBtnNext.onclick = nextMusic;
}
function playMusic(){
audio.play();
}
function pauseMusic(){
audio.pause();
}
/* function prevMusic(){
if(currentNum>1){
currentNum--;
}
audio.src="music/"+currentNum+".mp3";
console.log(audio.src);
objSpNum.innerText=currentNum;
}
function nextMusic(){
if(currentNum<3){
currentNum++;
}
audio.src="music/"+currentNum+".mp3";
console.log(audio.src);
objSpNum.innerText=currentNum;
} */
var a=["一支榴莲-海底", "买辣条也用券-起风了", "陈奕迅-孤勇者"]
function prevMusic(){
if(currentNum==1) {
currentNum=a.length;
}else{
currentNum--;
}
audio.src="music/"+currentNum+".mp3";
console.log(audio.src);
objSpNum.innerText=a[currentNum- 1];
playMusic();
}
function nextMusic(){
currentNum++;
if(currentNum>a.length) {
currentNum=1 ;
}
audio.src="music/"+currentNum + ".mp3";
console.log(audio.src);
objSpNum.innerText=a[currentNum- 1];
playMusic();
}



Disclaimer: The above articles are added by users themselves and are only for typing and communication purposes. They do not represent the views of this website, and this website does not assume any legal responsibility. This statement is hereby made! If there is any infringement of your rights, please contact us promptly to delete it.

字符:    改为:
去打字就可以设置个性皮肤啦!(O ^ ~ ^ O)