小程序背景音乐 的播放和暂停 最新版API

      
   const backgroundAudioManager = wx.getBackgroundAudioManager();
        var isPlay = this.data.isPlay;//在data中定义isPlay=false
        if (isPlay) {
            backgroundAudioManager.pause();//暂停
        
this.setData({
             isPlay = false
           })
        } else {
            backgroundAudioManager.title = '此时此刻';
            // backgroundAudioManager.epname = '此时此刻';
            backgroundAudioManager.singer = '许巍';
            backgroundAudioManager.coverImgUrl = 'https://p3fx.kgimg.com/stdmusic/20160909/20160909064838685290.jpg';
            backgroundAudioManager.src = 'https://win-web-nf01-sycdn.kuwo.cn/6482b5ee33641f36180011298801d00e/5dfa09e9/resource/n1/70/9/2628586107.mp3';
            this.data.isPlay = true;
        }
 
 
播放不了可能是音乐链接失效了;

猜你喜欢

转载自www.cnblogs.com/duokexiao/p/12061700.html