真机播放不了音频了
发布于 6 年前 作者 junjiang 12483 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)

开发好的功能,在2019-01-08那天在真机上还能正常播放,今天不能在真机上正常播放了。但是目前在微信开发者工具中正常播放

  • 预期表现

希望正常播放

  • 复现路径
  • 提供一个最简复现 Demo

playAudio() {

let audioCtx = wx.createInnerAudioContext();

let src = this.data.tempPath;

console.log(src);

audioCtx.src = src;

this.setData({

‘audioCtx’: audioCtx,

‘currentDuration’: ‘00:00’,

‘percentage’: 0

});

audioCtx.play();

audioCtx.onPlay(() => {

let totalTime = this.data.duration;

let count = 0;

this.setData({

‘play’: true

});

let audio = setInterval(() => {

if (count >= totalTime) {

audioCtx.pause();

clearInterval(audio);

this.setData({

‘play’: false,

‘percentage’: 100

});

} else {

let showDuration;

count++;

let min = parseInt(count / 60);

let senconds = Math.ceil(count % 60);

let newMin, newSenconds;

if (min < 10) {

newMin = ‘0’ + min;

} else {

newMin = min;

}

if (senconds < 10) {

newSenconds = ‘0’ + senconds;

} else {

newSenconds = senconds;

}

showDuration = newMin + ‘:’ + newSenconds;

this.setData({

‘currentDuration’: showDuration,

‘percentage’: (count / totalTime) * 100

});

}

}, 1000);

this.setData({

‘audioInterval’: audio

});

})

},

3 回复

我的真机也不能播放音频,在模拟器上可以正常播放,真机上播放官方demo上的链接,需要插上耳机才有声音,拔下耳机再插上就没有声音了,播放本地音频插不插耳机都没有声音,以上,在模拟器上都有声音

不能播放报错信息是什么?麻烦提供能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

我也遇到了相同的问题,也是用的wx.createInnerAudioContext(),有时候语音会正常播放,有时候没有播放,且未报任何错误,下面是我的代码,我的机型是iphone6

var bgm = wx.createInnerAudioContext();

bgm.autoplay = true;

bgm.loop = false;

bgm.src =“mp3/1.mp3”;

回到顶部