With the help from this question Use of reference to calling object (this) using HTML5 audio and jQuery.
Editing it I got the playlist that I wanted, it works perfectly on Crome and Safari but it won't play at all in other browsers, understable, since not all browsers support MP3 files. (Tested IE and Firefox; audio not playing, tested Safari with my iPod and no issue) But it's odd that IE won't play the audio when it does support MP3.
This is what I came up with editing the question linked above. I integrated jQuery to give a different style to the button, making it look more like the YouTube Play/Pause button.
Better example here: Playlist
I tried to use jQuery to change the src link in the audio like this
this.next = function (){
count++;
if(count == 2){count = 0;}
$('#uhh').attr('src', 'http://daokun.webs.com/play'+count+'.mp3');
$('#uhh2').attr('src', 'http://daokun.webs.com/play'+count+'.ogg');
};
And changing the <audio>
tag into this:
<audio id="aud" autoplay autobuffer>
<source id="uhh2" src="http://daokun.webs.com/play0.ogg" type="audio/ogg" />
<source id="uhh" src="http://daokun.webs.com/play0.mp3" type="audio/mpeg" />
</audio>
To make it crossbrowser but after the song changes it won't change the src
of the <source>
tags.
I also tried to edit the next function like this:
this.next = function (){
count++;
if(count == 2){count = 0;}
uhh = 'http://daokun.webs.com/play'+count+'.mp3';
uhh2 = 'http://daokun.webs.com/play'+count+'.ogg';
};
And add variables:
var uhh = $('#uhh').attr('src'),
uhh2 = $('#uhh2').attr('src');
Tried this aswell and still nothing.
var uhh = document.getElementById('aud').firstChild,
uhh2 = document.getElementById('aud').lastChild;
Didn't work so I edited it into this:
var uhh = document.getElementById('uhh'),
uhh2 = document.getElementById('uhh2');
The next function into:
this.next = function (){
count++;
if(count == 2){count = 0;}
uhh.src = 'http://daokun.webs.com/play'+count+'.mp3';
uhh2.src = 'http://daokun.webs.com/play'+count+'.mp3';
};
Assigning IDs to the two <source>
s (uhh and uhh2) but nothing.
I've noticed by checking the source code with Chrome that the src links on the two <source>
DOES change, but the issues is that the MP3 files aren't "loaded" into the page, by checking the resources tab. While using the <audio>
tag only the new MP3 files are "loaded" into the page and played.
So what is that I'm doing wrong? Or what's happening that it doesn't work?