I am trying to figure out how to display an image inside of a div that corresponds to the song that is playing in the playlist. Right now I only have the image showing IF the person has actually CLICKED a song, but I would like it to show the image when the code shifts from one song to the next automatically. I do not know how to do that as I am very new to jquery here are the relevant snippets.
This is just a snippet of the playlist:
<li>
<a href="audio/02.mp3"onclick="changeImg('audio/2.jpg');" >
Above All - Michael W. Smith
</a>
</li>
and this is these are the scripts used(which by the way, I am sure can be condensed in a very big way - but I have not attempted this as of yet!
<script>
$(document).ready(function () {
init();
function init(){
var current = 0;
var audio = $('#audio');
var playlist = $('#playlist');
var tracks = playlist.find('li a');
var len = tracks.length - 1;
var imghol = document.getElementById("imageHolder");
audio[0].volume = .10;
audio[0].play();
playlist.on('click','a', function(e){
e.preventDefault();
link = $(this);
current = link.parent().index();
run(link, audio[0]);
});
audio[0].addEventListener('ended',function(e){
current++;
if(current == len){
current = 0;
link = playlist.find('a')[0];
}else{
link = playlist.find('a')[current];
}
run($(link),audio[0]);
});
}
function run(link, player){
player.src = link.attr('href');
par = link.parent();
par.addClass('active').siblings().removeClass('active');
player.load();
player.play();
}
});
</script>
<script type="text/javascript">
function changeImg(image){
var imghol = document.getElementById("imageHolder");
imghol.src = image;
}
</script>
So far everything works GREAT, but as I said - I would LIKE to have the image that corresponds to the song automatically switch to another image when the song auto plays a different song.
The image showing method was taken from this site where someone else asked how to show an image when clicking on a list item, and I adapted the answer to fit what I needed it to show - but cannot figure out to get it to auto show!
Thanks :)