文章

博客外链播放器-随机播放

  • 之前在博客上放了首歌,后来发现想听的歌实在是太多了,但是放歌单又觉得臃肿,所以有了随机播放这个想法。
<div id="random-music"></div>
<script>
    // 存储所有音乐的 ID
    const musicIds = [
        1843680436, 
        1954090536, 
        1413863166
    ];

    // 随机选择一个 ID
    const randomId = musicIds[Math.floor(Math.random() * musicIds.length)];

    // 生成 iframe 并插入到页面
    const iframe = `<iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width="200" height="86" src="//music.163.com/outchain/player?type=2&id=${randomId}&auto=0&height=66"></iframe>`;
    document.getElementById("random-music").innerHTML = iframe;
</script>

把整串代码放到博客小工具即可。

  • 这里使用的是网易云的外链播放器,你可以手动调整宽高。把你需要随机播放的所有歌曲id放入列表即可。

0 条评论