ios下InneraudioContext无法播放?
发布于 5 年前 作者 slin 1642 次浏览 来自 官方Issues

//音频播放

const inneraudioContext = wx.createInnerAudioContext(); // 创建音频播放

let backgroundContext = wx.getBackgroundAudioManager();// 创建获取音频的


 audioplay: function (e) {
   let that = e.this;
   var src = e.currentTarget.dataset.audio;
   var mediaid = e.currentTarget.dataset.mediaid;  // 音频的ID
   var indexid = e.currentTarget.dataset.indexid  // 列表项ID
   var media = e.target.dataset.audiomedia;
   console.log(indexid)
    
   inneraudioContext.autoplay = true;
   inneraudioContext.src = src;
   var res= wx.getSystemInfoSync()
   if(res.platform=='ios'){
     console.log('ios')
     inneraudioContext.obeyMuteSwitch = false;
      
   }
    
   setTimeout(() => {
     inneraudioContext.play();
     inneraudioContext.currentTime
     inneraudioContext.onTimeUpdate(() => {
       console.log(inneraudioContext.duration)   //总时长
       // this.setData({
       //   // audiotime: inneraudioContext.duration.toFixed(0)+'s',
       //   isactive: indexid
       // })
       console.log('开始播放!代码')
     })
 
   }, 500)
   inneraudioContext.onPlay((res)=>{
     console.log('音频播放')
     this.setData({
       isactive: indexid,
        // 通过判断是不是当前的ID 如果是则后对比为true
     })
     speaking.call(this)
   })
 
   inneraudioContext.onPause((res) =>{
     console.log("pause")
     this.setData({
       isactive:indexid+"pause"
     })
     clearInterval(this.timer)
   })
   inneraudioContext.onEnded((res) => {
     console.log("音频停止了")
     clearInterval(this.timer)
     this.setData({
       isactive: indexid +"stop",
       // index_image:1
       // audiotime:''
     })
      
      
   })
   inneraudioContext.onError((res) => {
     console.log(res.message)
     console.log(res.errCoder)
   })
 
   clearInterval(this.timer)

 },


<!-- 语音 --->
              <view  wx:if="{{media.fileType =='aac'}}" class="audioView">
              <cover-view wx:if="{{media.fileType =='aac'}}" wx:key="this" data-indexid="{{item_id}}" data-audiomedia="{{note.media}}" data-mediaid="{{media.id}}" class="audioclass"  bindtap="audioplay"  data-audio="{{media.public_url}}" >
                <!--默认状态--->
                <!-- <cover-image  class="audioImg"  style=""   src="{{isactive==item_id?'../../images/audioImgRun.gif':'../../images/audio.png'}}"  transform="{{transform}}"></cover-image> -->
                <cover-image class="audioImg"  style="{{isactive==item_id?'display:none':''}}"   src="../../images/audio.png"></cover-image>
                
                <cover-view wx:if="{{isactive==item_id}}">
                 <cover-image wx:if="{{index_image==0}}" class="audioImg" style="" src="../../images/audio.png"></cover-image>
                <cover-image wx:if="{{index_image==1}}"  class="audioImg"  style=""   src="{{'../../images/audio1.png'}}"  ></cover-image>
                <cover-image wx:if="{{index_image==2}}" class="audioImg" style="" src="../../images/audio2.png"></cover-image>
                <cover-image wx:if="{{index_image==3}}" class="audioImg" style="" src="../../images/audio.png"></cover-image>
              <cover-view class="audioText">{{note.voiceTime!=null? note.voiceTime:'0'}}s </cover-view>   
</cover-view>
                <!-- <cover-view class="audioText">{{isactive==item_id?audiotime:''}} </cover-view>  -->
            <cover-view class="audioText">{{note.voiceTime!=null? note.voiceTime:'0'}}s </cover-view>    
              </cover-view>

在ios下无法播放,播放打印信息为undefine     在模拟器和安卓都可以播放出来声音

1 回复

麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

回到顶部