收藏
回答

安卓 createInnerAudioContext 播放失败

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug createInnerAudioContext 客户端 6.7.3 2.3.0 [173]

- 当前 Bug 的表现(可附上截图)

安卓播放失败,ios 与调试工具正常

- 预期表现

所有音频播放正常

- 复现路径


- 提供一个最简复现 Demo

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    audio: {
      type: Object,
      value: {}
    }
  },
 
  pageLifetimes: {
    hide: function () {
      this.innerAudioContext.stop()
    }
  },
 
  /**
   * 组件的初始数据
   */
  data: {
    playing: false,
    dur: 0,
  },
 
  ready: function () {
    this.innerAudioContext = wx.createInnerAudioContext()
    this.innerAudioContext.src = 'http://tbvideo.ixiaochuan.cn/zyad/07/a0/78ac-c7e0-11e8-8d60-00163e00c638'
    this.innerAudioContext.obeyMuteSwitch = false
    this.innerAudioContext.volume = 1
    this.setData({
      dur: this.properties.audio.dur || 0,
    })
 
    this.innerAudioContext.onPlay(() => {
      console.log('play')
    })
 
    this.innerAudioContext.onTimeUpdate((e) => {
      this.setData({
        dur: Math.floor(this.innerAudioContext.duration - this.innerAudioContext.currentTime) > 0 ? Math.floor(this.innerAudioContext.duration - this.innerAudioContext.currentTime) : 0
      })
    })
 
    this.innerAudioContext.onEnded(() => {
      this.setData({
        dur: Math.floor(this.properties.audio.dur),
        playing: false,
      })
    })
 
    this.innerAudioContext.onWaiting(() => {
      console.log('正在缓冲...')
    })
 
    this.innerAudioContext.onError((res) => {
      console.log(res.errMsg)
      console.log(res.errCode)
    })
  },
 
  detached: function () {
    this.innerAudioContext.destroy()
    this.innerAudioContext = null
  },
 
  /**
   * 组件的方法列表
   */
  methods: {
    playAudio: function (e) {
      const { playing } = this.data
      if (playing) {
        this.innerAudioContext.pause()
        this.setData({
          playing: false,
        })
      } else {
        this.innerAudioContext.play()
        this.setData({
          playing: true,
        })
      }
    },
  }
})


回答关注问题邀请回答
收藏

3 个回答

  • 僵尸浩
    僵尸浩
    2018-10-15

    你好,请问可以提供一下无法播放时的控制台输出吗

    2018-10-15
    有用
    回复 3
    • 2018-10-15

      无法播放的时候控制台并没有输出的

      2018-10-15
      1
      回复
    • 白日梦想家
      白日梦想家
      2018-11-08

      我看日志中有这个报错:wx.createInnerAudioContext is not a function. (In 'wx.createInnerAudioContext()', 'wx.createInnerAudioContext' is undefined); [Component] Lifetime Method Error @ components/audio/audio#ready

      2018-11-08
      回复
    • 咿呀呀
      咿呀呀
      2019-03-19

      的确,有些 url 的音频无法播放

      2019-03-19
      1
      回复
  • 禾店短剧系统
    禾店短剧系统
    2021-05-27

    先将服务器端传来的mp3音频下载到本地临时地址,再进行播放。

    2021-05-27
    有用 1
    回复
  • 2018-10-15

    麻烦帮我看下问题,https://developers.weixin.qq.com/community/develop/doc/0006c2d89fc3c036cb77c75835bc00

    同一个域名下,一个链接播放没问题,另一个链接却播放没有反应,也没有输出错误log,我测试的机型是mi6x  请问是什么原因? (当然链接直接点击是可以播放的!如这两个链接:可以的:

    https://sq.ztloft.com/wave/B854EC109ACBC346.mp3   不可以的:

    https://sq.ztloft.com/wave/4ED9320062EF362A.mp3


    )我里面有代码片段,麻烦给帮我解答一下大神,谢谢。

    2018-10-15
    有用
    回复
登录 后发表内容