网友真实露脸自拍10p,成人国产精品秘?久久久按摩,国产精品久久久久久无码不卡,成人免费区一区二区三区

小程序模板網

小程序實現播放器功能

發布時間:2021-06-02 11:44 所屬欄目:小程序開發教程
實例:一個簡單的播放器效果。
實現的功能:
1點擊播放按鈕。音頻開始播放。
2播放的同時,進度條在不停的更新走動
3點擊暫停按鈕,音頻停止播放
4當音頻播放完畢以后,進度條再次回到原點
5當拖滑動滑塊以后,松開滑塊,進度條繼續走動,音頻從滑塊松開的位置播放,直至播放結束
html:
<!--進度條-->
<viewclass="progresswrap">
<sliderclass="drag"step="10"value="{{curTimeVal}}"max="{{duration}}"
backgroundColor="#373636"activeColor="#FF1744"bindchange="slideBar"/>
</view>
<!--控制按鈕-->
<viewclass="btns">
<viewbindtap='play'><imagesrc="{{playSrc}}"></image></view>
<viewbindtap='pause'><imagesrc="{{pauseSrc}}"></image></view>
</view>
 
js
const innerAudioContext = wx.createInnerAudioContext();
Page({
duration:0,
curTimeVal:0,
})
onLoad: function:(){
wx.request({
url: utils.baseUrl + "/message/get?sessionID=" + sessionID + "&id=" + id,
success: function (res) {
var resData = res.data.data
var audioSrc ="https://www.rujian.vip"+resData.resourceURL;
that.setData({
contResponseArr: resData,
audioSrc: audioSrc
})
innerAudioContext.src = audioSrc;
}
})
},
play: function (e) {
var that=this;
innerAudioContext.play();
innerAudioContext.onPlay((res) =>
that.updateTime(that)
}) //沒有這個事件觸發,無法執行updatatime
}
pause:function(){
innerAudioContext.pause();
},
updateTime:function(that){
innerAudioContext.onTimeUpdate((res) => {
//更新時把當前的值給slide組件里的value值。slide的滑塊就能實現同步更新
console.log("duratio的值:", innerAudioContext.duration)
that.setData({
duration: innerAudioContext.duration.toFixed(2) *100,
curTimeVal: innerAudioContext.currentTime.toFixed(2) *100,
})
 
})
//播放到最后一秒
if (innerAudioContext.duration.toFixed(2) - innerAudioContext.currentTime.toFixed(2) <= 0) {
that.setStopState(that)
}
 
innerAudioContext.onEnded(() => {
that.setStopState(that)
})
},
//拖動滑塊
slideBar:function(e){
let that=this;
var curval=e.detail.value; //滑塊拖動的當前值
innerAudioContext.seek(curval); //讓滑塊跳轉至指定位置
innerAudioContext.onSeeked((res)=>{
this.updateTime(that) //注意這里要繼續出發updataTime事件,
})
 
},
setStopState:function(that){
that.setData({
curTimeVal: 0
})
innerAudioContext.stop()
}

效果如下:


易優小程序(企業版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.xiuhaier.com/wxmini/doc/course/25917.html 復制鏈接 如需定制請聯系易優客服咨詢:800182392 點擊咨詢
QQ在線咨詢
AI智能客服 ×