收藏
回答

如何做到只播放点击的音乐,让其他音乐都停止播放?

在做个音乐播放器,列表里有很多音乐。现在是每点击一个就播放,其他的不会停止。如何做到只播放点击的音乐,让其他音乐都停止播放

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

3 个回答

  • 机智的小东
    机智的小东
    2022-12-30

    创建一个全局音频管理器,并在onLoad里设置不与其他音频混播,就可以实现只播放一个音频。


    文档:

    wx.createInnerAudioContext

    https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/wx.createInnerAudioContext.html

    wx.setInnerAudioOption

    https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/wx.setInnerAudioOption.html


    参考代码:

    const innerAudioContext = wx.createInnerAudioContext() // 创建全局音频管理器
    
    
    Page({
      onLoad() {
        // 音频全局配置
        wx.setInnerAudioOption({
          mixWithOther: false// 是否与其他音频混播
        })
      },
      // 播放音乐
      play_music() {
        innerAudioContext.src = 'http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E061FF02C31F716658E5C81F5594D561F2E88B854E81CAAB7806D5E4F103E55D33C16F3FAC506D1AB172DE8600B37E43FAD&fromtag=46' // 音频的路径
        innerAudioContext.play() // 播放
        // innerAudioContext.pause() // 暂停
        // innerAudioContext.stop() // 停止
      },
    
    
    })
    


    2022-12-30
    有用 1
    回复
  • ꧁꫞꯭前男友🙈꫞꧂
    ꧁꫞꯭前男友🙈꫞꧂
    发表于小程序端
    2022-12-05

    你的问题解决了没有

    2022-12-05
    有用
    回复
  • 睡前原谅一切
    睡前原谅一切
    2022-09-19
    你写个代码片段出来 我给你改下。
    
    https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html
    
    2022-09-19
    有用
    回复
登录 后发表内容