Нужно ли использовать строгие инструкции для этих функций?Он также ожидает «:» вместо «.»для window.onload?Он также говорит, что «е» не определено, однако я использую его как событие функции.Плюс неисправимая синтаксическая ошибка?Это простой аудиоплеер для сайта.
var audio = new Audio();
var audioPlayer = {
albumId: 0,
audioTrack: 0,
currentFolder: "",
albums: [
{
artist: "Post Malone",
album: "Beerbongs & Bentleys",
folder: "Beerbongs & Bentleys",
graphic: "Beerbongs & Bentleys/b&bart.png",
songs: ["Better Now.mp3", "Psycho ft. Ty Dolla $ign.mp3", "Rockstar ft. 21 Savage.mp3"],
songTitles: ["Better Now", "Psycho ft. Ty Dolla $ign", "Rockstar ft. 21 Savage"]
}
],
selectAlbum: function(e){
console.log(audioPlayer.albumId);
$("#tracks").empty();
$("h1").text(audioPlayer.albums[audioPlayer.albumId].album);
$("#track > span").text(audioPlayer.albums[audioPlayer.albumId].songTitles[audioPlayer.audioTrack]);
$(".album_cover > img").attr("src", "albums/" + audioPlayer.albums[audioPlayer.albumId].graphic);
$("#status").text("Ready to Play");
$.each(audioPlayer.albums[audioPlayer.albumId].songTitles, function(index, item){
$("#tracks").append("<li>" + audioPlayer.albums[audioPlayer.albumId].songTitles[index] + "</li>");
});
},
playAlbum: function(){
audio.src = "../albums/" + audioPlayer.albums[audioPlayer.albumId].folder + "/" + audioPlayer.albums[audioPlayer.albumId].songs[audioPlayer.audioTrack];
audio.play();
},
changeTrack: function(direction){
console.log(direction)
if(direction === "forward" && audioPlayer.audioTrack < audioPlayer.albums[audioPlayer.albumId].songs.length - 1){
audioPlayer.audioTrack++;
}
if(direction === "back" && audioPlayer.audioTrack < audioPlayer.albums[audioPlayer.albumId].songs.length + 1){
audioPlayer.audioTrack--;
}
},
window.onload = function(){
audioPlayer.selectAlbum()
$("#status").text("Playing");
}
$(document).on("click", "#albums > div > button",
function(e){
var album = this.id.split("_");
audioPlayer.albumId = parseInt(album[1]) - 1;
audioPlayer.selectAlbum();
});
};