JS audioplayer无法正常工作 - 无法加载资源

时间:2018-01-02 15:32:26

标签: javascript audio-player

我正在我的网页上创建一个音频播放器,js的一部分是:

    var songs = ["The Violence.mp3", "Welcome To The Breakdown.mp3", "Re-education.mp3"]

var songTitle = document.getElementById('songTitle');
var songSlider = document.getElementById('songSlider');
var currentTime = document.getElementById('currentTime');
var duration = document.getElementById('duration');
var volumeSlider = document.getElementById('volumeSlider');
var nextSongTitle = document.getElementById('nextSongTitle');

var song = new Audio();
var currentSong = 0;

window.onload = loadSong;

function loadSong () {
    song.src = "" + songs[currentSong];
    songTitle.textContent = (currentSong + 1) + ". " + songs[currentSong];
    nextSongTitle.innerHTML = "<b>Next Song: </b>" + songs[currentSong + 1 % songs.length];
    song.volume = volumeSlider.value;
    song.play();
    setTimeout(showDuration, 1000);
}

它不起作用,似乎无法找到文件,控制台写道:

  

获取文件:/// C:/Users/Kaja/Documents/%C5%A1kola/ZATLA/programov%C3%A1n%C3%AD/semestralka/The%20Violence.mp3 net :: ERR_FILE_NOT_FOUND“

我理解,但我非常确定mp3文件在这里,有谁知道如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

修正了问题确实存在于文件名中(我只是愚蠢而且没有注意到这首歌的名字实际上是The Violence.mp3)。