如何在网站中嵌入网易云音乐播放器

Tag: Others  Posted on 2020-04-15 11:09:58 Edited on 2020-04-24 10:41:50

示例

代码

<div id="list"></div>

<script>
    let data = [
        {name:"年少有为", id:"1293886117"},
        {name:"下山", id:"1404885266"}
        ];
    let list = document.getElementById("list");
    data.forEach(function(song){
        let audio = document.createElement("audio");
        audio.setAttribute("controls", "controls")
        let source = document.createElement("source");
        source.setAttribute("src", `http://music.163.com/song/media/outer/url?id=${song.id}.mp3`);
        audio.appendChild(source);
        list.appendChild(audio);
    });
</script>

其中的歌曲 id 的获取方法:打开网页版,url 上写的很清楚。