I am renovating an old jPlayer implementation - jPlayer 1.2.0, jQuery 1.4. I'd supply a link, but my development version is on an intranet.
My setup consists of a list of songs in a table, with a "play preview" button next to each one. Originally I set it up with each button having its own individual jPlayer instance, but once the songs began to multiply, this became ridiculously bloated and slow. So instead, my goal is to instantiate jPlayer for each preview player only at the moment it is needed.
For reference, each "play" link looks like this: "<a href="
http://audio/file.mp3" title="22">Play Preview</a>. As you can see from the code, the href and title attributes are pulled from the link to construct the player when the link is clicked, with the number in the title attribute serving as an ID to differentiate between multiple players on the page.
My problem is with autoplay. The code below works perfectly in Chrome and IE9, but not in Firefox - indicating to me that there is some problem with the Flash fallback. However, if I remove the .jplayer("play") directive inside the ready: function, the player works in Firefox. I just have to click the button twice because there's no autoplay on the instantiated player - which is not acceptable for our users.
Using the code below in Firefox, the Play button disappears and is replaced with the Pause button as if the audio is playing, but no sound comes out.
Any help would be greatly appreciated.
$('.jp-preview-play').click(function(e){
e.preventDefault();
var audioPath = $(this).attr('href');
var ssId = $(this).attr('title');
var playerId = "#jquery_jplayer_" + ssId;
var pauseId = "jplayer_pause_" + ssId;
var playId = "jplayer_play_" + ssId;
$(playerId).jPlayer({
volume: 50,
swfPath: "assets/js/jplayer",
ready: function () {
this.element.jPlayer("setFile", audioPath).jPlayer("play");
}
})
.jPlayer("cssId", "pause", pauseId)
.jPlayer("cssId", "play", playId)
.jPlayer("onSoundComplete", function() {
this.element.jPlayer("stop");
});
});