连续播放多段视频与音频,开发工具正常,真机会出错
真机会第一段视频与音频是正常的,自动切换时,视频可以循环,但是每次循环,视频都会有个加载的小圈圈,声音出来不到一秒就没有声音。奇怪的是点击暂停键,声音就会出来?(期间没有报错)哪位大神知道?
videoContext = wx.createVideoContext(‘myVideo’);
audioCtx = wx.createAudioContext(‘myAudio’);
真机会第一段视频与音频是正常的,自动切换时,视频可以循环,但是每次循环,视频都会有个加载的小圈圈,声音出来不到一秒就没有声音。奇怪的是点击暂停键,声音就会出来?(期间没有报错)哪位大神知道?
videoContext = wx.createVideoContext(‘myVideo’);
audioCtx = wx.createAudioContext(‘myAudio’);
onMusicTap(event) { let that = this let node = this.data.node let isPlayingMusic = node.isPlayingMusic // let audioProgress = app.globalData.g_trackAudioProgress.get(node.id) const backgroundAudioManager = app.globalData.backgroundAudioManager node.isPlayingMusic = this.data.node.isPlayingMusic node.stopPoint = processTotalDuration(this.data.node.listened) backgroundAudioManager.onTimeUpdate(e => { that.setData({ duration: processTotalDuration(backgroundAudioManager.duration), currentTime: processTotalDuration(backgroundAudioManager.currentTime), percent: parseInt(100 * (backgroundAudioManager.currentTime / backgroundAudioManager.duration)) }) app.globalData.g_trackAudioProgress.set(node.id, { duration: backgroundAudioManager.duration, stopPoint: backgroundAudioManager.currentTime }) if (app.globalData.g_trackAudioProgress.get(node.id)) { // 循环播放 TODO: if (app.globalData.g_trackAudioProgress.get(node.id).stopPoint >= (app.globalData.g_trackAudioProgress.get(node.id).duration) - 3) { app.globalData.g_trackAudioProgress.set(node.id, { duration: backgroundAudioManager.duration, stopPoint: 0, }) } } console.log(app.globalData.g_trackAudioProgress.get(node.id)) }) // 穿透:改变数据源(course-text)里 this.triggerEvent('customevent', node, { bubbles: true }) // 再加事件绑定 this.setMusicMonitor() if (isPlayingMusic) { // 暂停回调 backgroundAudioManager.pause(e => { console.log('will plause') }) } else { backgroundAudioManager.src = `${node.content}` backgroundAudioManager.title = node.title // 首次点击,从node中获取时间,之后从audioProgress获取 backgroundAudioManager.startTime = that.data.isFirstTap ? convertTimeToSeconds(that.data.node.listened) : app.globalData.g_trackAudioProgress.get(node.id) && app.globalData.g_trackAudioProgress.get(node.id).stopPoint that.setData({ isFirstTap: false }) console.log('will play') }
setMusicMonitor() { const backgroundAudioManager = app.globalData.backgroundAudioManager let that = this let node = this.data.node //点击播放图标和总控开关都会触发这个函数 wx.onBackgroundAudioPlay(e => { console.log('playing...') node.isPlayingMusic ? null : that.onMusicTap() }) wx.onBackgroundAudioPause(e => { console.log('pausing...') node.isPlayingMusic ? that.onMusicTap() : null }) wx.onBackgroundAudioStop(e => { if (app.globalData.g_trackAudioProgress.get(node.id)) { // 循环播放 TODO: if (app.globalData.g_trackAudioProgress.get(node.id).stopPoint >= app.globalData.g_trackAudioProgress.get(node.id).duration - 3) { app.globalData.g_trackAudioProgress.set(node.id, { duration: backgroundAudioManager.duration, stopPoint: 0 }) } } console.log('stopping...', app.globalData.g_trackAudioProgress.get(node.id)) node.isPlayingMusic ? that.onMusicTap() : null }) }, |
音频播放模拟机没问题,真机老是少播放2秒,求助SOS