meting插件音乐播放不中断


在meting-js里面加上这样一段代码就可以实现跳转页面不切歌的功能了

_loadPlayer(a) {
    let b = {audio: a, mutex: !0, lrcType: this.meta.lrcType || 3, storageName: "metingjs"};
    if (a.length) {
        let a = _objectSpread({}, b, this.config);
        for (let b in a) ("true" === a[b] || "false" === a[b]) && (a[b] = "true" === a[b]);
        let c = document.createElement("div");
        a.container = c, this.appendChild(c), this.aplayer = new APlayer(a);
        window.onbeforeunload = e => {
            //监听是否刷新,然后将音乐的索引和时间写入本地
            localStorage.setItem('music_play', this.aplayer.audio.paused)//离开前记录的音乐状态
            localStorage.setItem('music_time', this.aplayer.audio.currentTime)//离开前记录的音乐时间
            localStorage.setItem('music_index', this.aplayer.list.index)//离开前记录的音乐
        };
        let play = localStorage.getItem('music_play')
        let music_index = localStorage.getItem('music_index')
        let time = localStorage.getItem('music_time')

        //不管要不要放
        this.aplayer.list.switch(music_index);
        setTimeout(() => {
            this.aplayer.seek(parseInt(time) + 1);
        }, 300)
        //判断是否播放
        if (play === "false") {
            console.log('播放')
            this.aplayer.play();
        }

    }
}

评论
  目录