Reputation: 21
This is the code I have now, it's the code for a playlist with two songs :
$("#audio-mix").click(function() {
var playlistPoster = "img/playlist_poster.jpg";
myPlaylist.setPlaylist([
{
title:"Song #01",
artist:"Artist",
mp3:"music/song_01.mp3",
oga:"music/song_01.ogg",
poster: playlistPoster
},
{
title:"Song #02",
artist:"Artist",
mp3:"music/song_01.mp3",
oga:"music/song_01.ogg",
poster: playlistPoster
}
]);
});
I added a variable playlistPoster so I don't have to write the link for the poster in every song.
But the same songs will be inserted in several other playlists with different order, new songs etc and I want to shorten the code.
I also want each playlist to have its unique "poster".
This code before the playlist worked :
var playlistPoster;
var song_01 = {
title:"Song #01",
artist:"Artist",
mp3:"music/song_01.mp3",
oga:"music/song_01.ogg",
poster: playlistPoster
}
But then I can't reset the playlistPoster variable for every playlist to display a different poster.
So I tried to put only this part in a variable :
title:"Song #01",
artist:"Artist",
mp3:"music/song_01.mp3",
oga:"music/song_01.ogg"
And that's my problem I tried to wrap it with quotes, use a backslash for multi-lines, and other tricks but I either get an error or an undefined playlist entry.
What's wrong ? :D Thank you for your time :)
Upvotes: 1
Views: 240
Reputation: 21
This is what worked for me :
setting the variables :
var song_01 = {
title:"Song #01",
artist:"Artist",
mp3:"music/song_01.mp3",
oga:"music/song_01.ogg",
poster: "img/default.jpg"
}
var song_02 = {
title:"Song #02",
artist:"Artist",
mp3:"music/song_02.mp3",
oga:"music/song_02.ogg",
poster: "img/default.jpg"
}
The playlist code :
$("#audio-mix").click(function() {
myPlaylist.setPlaylist([
song_01,
song_02
]);
document.getElementById("jp_poster_0").src = "playlist_poster.jpg"; // Change the poster image
});
Upvotes: 1