August 15 2012
According to the docs of jPlayer http://www.jplayer.org/latest/developer-guide/#jPlayer-essential-formats, you are only supposed to use either mp3 or m4a. But in my case, I’m not sure which gets passed to the player from the database. So, I had to handle that in the script. Here’s what it looks like:
$("#jplayer").jPlayer({
ready: function() {
$("#jp_container .track-default").click();
},
supplied: "m4a, mp3, mv4"
});
When I wire up the handlers, I check the file extension before passing the URL to the setMedia method, like this:
$(".play").click(function(e) {
var filename = $(this).attr("href");
var ext = filename.split('.').pop();
if (ext == "m4a") {
$("#jplayer").jPlayer("setMedia", {
m4a: $(this).attr("href")
});
}
else {
$("#jplayer").jPlayer("setMedia", {
mp3: $(this).attr("href")
});
}
A little hacky, but it works!