我想在后台播放我的网页上的音乐播放列表,我使用的是 chrome我不需要控制台,我想要自动播放,但是,尽管我编写了自动播放,但音频仅从播放按钮开始安慰。这就是我在 HTML 中写的内容:
<div id="music_list">
<audio controls autoplay></audio>
</div>
在 JavaScript 中
(function () {
// Playlist array
var files = [
"ms4/14_1.30.mp3",
"ms4/20_20.mp3",
"ms4/21_34.mp3"
];
// Current index of the files array
var i = 0;
// Get the audio element
var music_player = document.querySelector("#music_list audio");
// function for moving to next audio file
function next() {
// Check for last audio file in the playlist
if (i === files.length - 1) {
i = 0;
} else {
i++;
}
// Change the audio element source
music_player.src = files[i];
}
// Check if the player is slected
if (music_player === null) {
throw "Playlist Player does not exists ...";
} else {
// Start the player
music_player.src = files[i];
// Listen for the music ended event, to play the next audio file
music_player.addEventListener('ended', next, false)
}
})();
我该如何解决这个问题?我对 HTML 和 JS 很陌生,但我陷入了这个问题。
LEATH
慕尼黑8549860
慕尼黑5688855
相关分类