问题
I'm integrating jplayer to play a selection of mp3 files triggered by an click event using jQuery. The code used to achieve this is:
$('.play-link').click(function() {
$("#jquery_jplayer_1").jPlayer("destroy");
srcFile = $(this).attr('href');
$("#jquery_jplayer_1").jPlayer({
ready: function (event) {
$(this).jPlayer("setMedia", {
mp3:srcFile
}).jPlayer("play");
},
swfPath: "http://www.mydomain.co.uk/swf/Jplayer.swf",
supplied: "mp3",
wmode: "window"
});
return false;
});
srcFile
is set from the href of the link clicked.
This all works fine in the various versions of IE and Chrome but not in Firefox. Using Firebug the swf is being loaded into the browser so the swfPath appears to be correct but nothing further happens when the player is initialised.
Is anybody able to shed any light on why this would not be working in Firefox alone?
Thanks
回答1:
MP3 files are not supported by Firefox and therefore jPlayer will not play them while running in the FF browser.
You must have .ogg audio files for jPlayer to work in Firefox. See below list of browsers and their respective compatible files:
HTML5 browsers and their supported audio file formats:
Firefox (OSX, Win): WEBMA, OGA
Safari (OSX, Win): MP3, M4A
Mobile Safari iOS4 (iPad, iPhone, iPod): MP3, M4A
Opera (OSX, Win): WEBMA, OGA
Chrome (OSX, Win): WEBMA, OGA, MP3, M4A
IE9 (Win): MP3, M4A (Can install the WebM codec.)
回答2:
Set 'solution' attribute. Make it compatible with IE9 as well.
var player = $("#jquery_jplayer_1").jPlayer({
ready: function (event) {
$(this).jPlayer("setMedia", {
mp3:srcFile
}).jPlayer("play");
},
swfPath: "http://www.mydomain.co.uk/swf/Jplayer.swf",
supplied: "mp3",
wmode: "window",
solution: navigator.userAgent.indexOf("Trident/5")>-1 ? "flash" : "html,flash"
});
来源:https://stackoverflow.com/questions/8248896/jplayer-not-playing-mp3-in-firefox