Joker
2020-01-20
加粗
标红
插入代码
插入链接
插入图片
上传视频
请 登录 后发表内容
关闭
新增或编辑超链接
链接地址
关闭
插入视频
视频链接
苹果七,苹果X;7.0.10;12.4.1, 13.3.0;
wx.setInnerAudioOption({
obeyMuteSwitch: false
})
var innerAudioContext = null;
Page({
/**
* 页面的初始数据
*/
data: {
formatedPlayTime: '00:00',
playStatus: true, //未播放的图片
imgDesc: { }
},
// 音频播放
musicStart: function(e) {
let that = this
this.setData({ playStatus: false })
innerAudioContext.src = this.getSrc(that);
console.log(this.getSrc(that))
innerAudioContext.play();
this.updateTime(that);
},
getSrc: function(that) {
return that.data.imgDesc.src
},
updateTime: function(that) {
innerAudioContext.onTimeUpdate((res) => {
that.setData({
formatedPlayTime: that.formatTime(innerAudioContext.currentTime)
})
})
if (innerAudioContext.duration.toFixed(2) - innerAudioContext.currentTime.toFixed(2) <= 0) {
that.setStopState(that)
}
innerAudioContext.onEnded(() => {
that.setStopState(that)
})
},
canel_handover() {
// innerAudioContext.offPause(); //取消录音暂停
innerAudioContext.pause(); //语音暂停
this.setData({
playStatus: true
})
},
setStopState: function(that) {
that.setData({
formatedPlayTime: "00:00",
playStatus: true, //图片展示为未播放
})
innerAudioContext.stop(); //
},
formatTime: (time) => {
time = Math.floor(time);
var m = Math.floor(time / 60).toString();
m = m.length < 2 ? '0' + m : m;
var s = (time - parseInt(m) * 60).toString();
s = s.length < 2 ? '0' + s : s;
return m + ':' + s;
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
let that = this
innerAudioContext = wx.createInnerAudioContext();
innerAudioContext.onError((res) => {
console.log(res.errMsg);
console.log(res.errCode);
});
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
let that = this;
this.setStopState(that)
innerAudioContext.destroy()
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
let that = this;
this.setStopState(that)
innerAudioContext.destroy()
},
})
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。待楼主反馈
2020-01-20
赞
回复
关闭
请选择投诉理由
广告内容
违法违规
恶意灌水内容
其他