求助:wx.createInnerAudioContext()停止当前播放的音频
发布于 4 年前 作者 jie95 20314 次浏览 来自 问答

求助:wx.createInnerAudioContext() 如何停止停止当前播放的音频,官方文档没有示例代码

//语音控制
audioControl: {
   /**
    * 播放语音
    * [@param](/user/param) audioUrl   语音路径
    */
   playAudio(that, audioUrl) {
       let innerAudioContext = wx.createInnerAudioContext();
       innerAudioContext.autoplay = true;
       innerAudioContext.obeyMuteSwitch = true;
       innerAudioContext.src = audioUrl;
       innerAudioContext.onPlay(() => console.log('开始播放'));
       innerAudioContext.onEnded(() => {
           that.setData({
               audioPlayState: false
           })
       });
       innerAudioContext.onError((res) => {
           console.log(res.errMsg);
           console.log(res.errCode);
       });
   },
   //暂停播放
   stopVoice(that, audioUrl){
       let innerAudioContext = wx.createInnerAudioContext();
       innerAudioContext.src = audioUrl;
       innerAudioContext.onPause(() => {
           console.log('暂停播放');
       })
       innerAudioContext.onError((res) => {
           console.log(res.errMsg);
           console.log(res.errCode);
       })
   }
},
8 回复

要同一个实例。你的代码不是同一个实例了

@GaleLiu 好的,谢谢

现在腾讯禁止阿里的东西,请使用腾讯云

请问下,wx.createInnerAudioContext()的src为什么用音频的阿里云的OSS会提示错误呢,你们用的是什么样的格式

那个实例innerAudioContext.pause()可停止

innerAudioContext.pause()这是暂停,不是停止

@ GermSir  我用的是 .mp3 格式的

求助,如何停止当前音频的播放,官方文档没有示例代码

回到顶部