麻烦大家帮我看看啊呢,
问题是:
点击“下一首”后还要手动点“播放当前”才可以真的播放,而我分明在“下一首”绑定的函数里调用了play函数。
也没报错,音源地址确定也没有问题。
首先是界面:
附上代码:
//js
audioNext: function () {
this.audioCtx.pause()
console.log(“audionext pause”)
index=index+1
if (index>2) {index=0}
this.setData({
index:index
})
this.audioCtx.play()
console.log(“to play audioNext”)
},
audioPlay: function () {
this.audioCtx.play()
console.log(“audio play begin”)
console.log(this.audioCtx);
console.log(“audio play end”)
},
audioPause: function () {
console.log(“audio pause begin”)
this.audioCtx.pause()
console.log(“audio pause end”)
},
audioFirst: function () {
this.audioCtx.pause()
console.log(“audionext pause”)
index=0
this.setData({
index:index
})
this.audioCtx.play()
},
onReady: function () {
this.audioCtx = wx.createAudioContext(‘myAudio’)
console.log(this.audioCtx)
},
//wxml
<view class=“title”>我与音乐</view>
<view class=“audio”>
<audio poster="{{songs[index].poster}}" name="{{songs[index].name}}" author="{{songs[index].author}}" src="{{songs[index].src}}" id=“myAudio” controls loop ></audio>
</view>
<view class=“query”>Hi~今天想听哪首歌?</view>
<view class=“query”>(点击下方黑框,按歌名选择)</view>
<picker range="{{songs}}"
range-key =“name” bindchange=“bindPickerChange” value="{{index}}" >
<view class=“playlist”>
<view class=“query2” >当前第{{(index+1)}}首:</view>
<view class= “border” > {{songs[index].name}} by {{songs[index].author}}</view>
</view>
</picker>
<view class=“btn”>
<button type=“primary” bindtap=“audioPlay” plain>播放当前
</button>
<button type=“primary” bindtap=“audioPause” plain>暂停</button>
<button type=“primary” plain bindtap=“audioNext”>下一首</button>
<button type=“primary” bindtap=“audioFirst” plain > 第一首</button>
<button type=“primary” bindtap=“audioStart” plain >重听</button>
</view>
<view class=“usermotto”>
<text class=“user-motto”>感谢聆听!</text>
</view>