使用APlayer+MetingJS方便快捷地为你的博客添加歌单
1、安装依赖
1 2
| yarn add hexo-tag-aplayer npm -i hexo-tag-aplayer --save
|
2、生成歌单
- 打开网易云音乐,将喜欢的歌都加入歌单,然后点击生成外链
- 网易云音乐
3、插入代码
/footer.ejs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css"><!--我的APlayer的样式https: <script src="https://unpkg.com/aplayer@1.10.1/dist/APlayer.min.js"></script><!--APlayer的依赖--> <script src="https://unpkg.com/meting@2/dist/Meting.min.js"></script><!--Meting的依赖--> <meting-js server="netease" type="playlist" autoplay=false lrc-type=3 fixed=true id="4926587734" theme="#ad7a86"> </meting-js> <script src="https://cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script> <script src="https://cdn.bootcss.com/jquery.pjax/1.9.6/jquery.pjax.min.js"></script> <script> ap = null Object.defineProperty(document.querySelector('meting-js'),"aplayer",{ set: function(aplayer) { ap=aplayer ready(); } }); isRecover = false; function ready(){ ap.on('canplay', function () { if(!isRecover){ if(localStorage.getItem("musicIndex") != null){ musicIndex = localStorage.getItem("musicIndex"); musicTime = localStorage.getItem("musicTime"); if(ap.list.index != musicIndex){ ap.list.switch(musicIndex); }else{ ap.seek(musicTime); ap.play(); localStorage.clear(); isRecover = true; } }else{ isRecover = true; } } }); }
window.onbeforeunload = function(event) { if(!ap.audio.paused){ musicIndex = ap.list.index; musicTime = ap.audio.currentTime; localStorage.setItem("musicIndex",musicIndex); localStorage.setItem("musicTime",musicTime); } }; </script>
|
- 修改上面id
- 也可以在/blog/themes/stellar/source/css/main.styl引用APlayer.min.css文件
1
| @import 'APlayer.min.css'
|