小程序
小游戏
企业微信
微信支付
扫描小程序码分享
https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/InnerAudioContext.html
2 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
你好,建议加上InnerAudioContext.onError(function callback)监听音频播放错误事件https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/InnerAudioContext.html
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
你好,建议加上InnerAudioContext.onError(function callback)排查下https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/InnerAudioContext.html
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
你好,建议加上InnerAudioContext.onError(function callback)监听音频播放错误事件https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/InnerAudioContext.html
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()
},
})
你好,建议加上InnerAudioContext.onError(function callback)排查下https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/InnerAudioContext.html