html52.com
我爱小程序-开发者交流社区

连续播放多段视频与音频,开发工具正常,真机会出错

问题模块 框架类型 问题类型 API/组件名称 终端类型 操作系统 微信版本 基础库版本
API和组件 小程序 Bug audio、video 客户端 6.6.5 1.9.97

真机会第一段视频与音频是正常的,自动切换时,视频可以循环,但是每次循环,视频都会有个加载的小圈圈,声音出来不到一秒就没有声音。奇怪的是点击暂停键,声音就会出来?(期间没有报错)哪位大神知道?

videoContext = wx.createVideoContext('myVideo');

audioCtx = wx.createAudioContext('myAudio');


网友回复

Elliot:

目前还没解决,安卓上很无奈;并且ios上强制写js触发播放完毕的UI更新。

forever:

解决了么?我也遇到了,ios10的播放音频,暂停,然后播放视频播放几秒之后就没有声音了,视频一直还在播,暂停或者拖进度之后就又有声音了,播视频的操作是把音频停止了,调用audio的stop()方法

Elliot:
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

娇华:

麻烦给个相关的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html),我们定位下问题

habbi:

https://developers.weixin.qq.com/blogdetail?action=get_post_info&lang=zh_CN&token=690657009&docid=000c4a5065c3d8a25166124445a400


我以前是调用背景音乐会出问题,后来改成了AudioContext才好,不知道你这里是为啥。

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付