一个函数里面多了一个if,就运行报错。把那个if单独拿出来用一个函数来封装,代码是一样的。就正常运行。为什么?头大。
if又不是else,为什么要和之前那个的花括号写在一排
这么多if,到底哪个if报错?
可以把第二个 if 改为 else if
songplay(state,value){
if(state.songdex===null){
console.log('数据为空')
}
else if(value=='low'){
if(state.songdex < state.datasong.length-1) {
state.songdex =state.songdex+1
console.log(“当前音频索引值",state.index)
state.audio.src=state.datasong[state.songdex].songsrc /∥载入当前上一首音频地址
state.picturesrc = state.datasong[state.songdex].picturesrc
state.audio.load()
}
}
else if(value=='per'){
if(state.songdex > 0){
state.songdex =state.songdex-1
console.log("当前音频索引值",state.index)
state.audio.src =state.datasong[state.songdex].songsrc //载入当前上一首音频
state.picturesrc = state.datasong[state.songdex].picturesrc
state.audio.load()
state.audio.play()
}
}
else{
state.songdex = value //存放当前在本数据组下音频索引值
state.audio.src=state.datasong[state.songdex].songsrc //载入当前音频地址
state.picturesrc =state.datasong[state.songdex].picturesrc //当前音频图片地址
state.audio.load()
state.audio.play()//当前播放状态
state.paused = state.audio.paused
state.ended = state.audio.ended
console.log("paused"+state.paused)
console.log("当前音频索引值",state.datasong[state.songdex+1].songsrc)
}
}