javascript jPlayer - 使用 setMedia() 设置媒体 URL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7401282/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jPlayer - Use setMedia() to set the media URL
提问by Pierre de LESPINAY
I'm trying to use jPlayer under Firefox 3.6 (Ubuntu)
我正在尝试在 Firefox 3.6 (Ubuntu) 下使用 jPlayer
function loadmedia() {
$('#jquery_jplayer_1').jPlayer('setMedia', {
mp3: 'media/audio/04-Piste_4_1.mp3',
});
}
$(document).ready(function () {
$('#jquery_jplayer_1').jPlayer({
ready: loadmedia,
swfPath: 'static/jPlayer',
errorAlerts: true,
supplied: 'mp3',
});
});
But it's telling me
但它告诉我
jPlayer 2.1.0 : id='jquery_jplayer_1' : Error!
Attempt to issue media playback commands, while no media url is set.
Use setMedia() to set the media URL.
Context: play
jPlayer 2.1.0:id='jquery_jplayer_1':错误!
尝试发出媒体播放命令,但未设置媒体 url。
使用 setMedia() 设置媒体 URL。
语境:玩
And doesn't play the file
并且不播放文件
You check an online example here
您在此处查看在线示例
回答by UpHelix
The main point of jPlayer is so that you can use html5 with flash fallback, so you should leverage the html5 of FF and chrome, not depending on it falling back to flash.
jPlayer 的主要目的是让您可以使用 html5 和 flash 回退,因此您应该利用 FF 和 chrome 的 html5,而不是依赖于它回退到 flash。
Firefox doesn't support mp3 on html5, they support ogg, which is better anyway. I always format each audio file I need to play for each browser, that way you can leverage html5 when its available, and you give your app a much better chance at loading the audio file, with 3 for each browser to choose from (not all get loaded, just the one it needs).
Firefox 不支持 html5 上的 mp3,它们支持 ogg,无论如何都更好。我总是格式化我需要为每个浏览器播放的每个音频文件,这样你就可以在 html5 可用时利用它,并且你给你的应用程序加载音频文件的更好机会,每个浏览器有 3 个可供选择(不是全部加载,只是它需要的那个)。
Use: .ogg for Chrome and Firefox, .m4a for Safari, and .mp3 for IE. See here
使用:.ogg 用于 Chrome 和 Firefox,.m4a 用于 Safari,.mp3 用于 IE。 看这里
Covert your audio files then try this:
隐藏你的音频文件然后试试这个:
function loadmedia(){
$('#jquery_jplayer_1').jPlayer('setMedia', {
oga: 'media/audio/04-Piste_4_1.ogg',
m4a: 'media/audio/04-Piste_4_1.m4a',
mp3: 'media/audio/04-Piste_4_1.mp3'
});
}
$(document).ready(function () {
$('#jquery_jplayer_1').jPlayer({
ready: loadmedia,
swfPath: 'static/jPlayer',
errorAlerts: true,
supplied: 'oga, m4a, mp3'//fyi, in your code you had a trailing comma here, that will break IE
});
});
EDIT:
编辑:
Saw this on the jPlayer site for the new audio demo: Link
在 jPlayer 网站上看到了这个新的音频演示:链接
Note that the {wmode:"window"} option is set to ensure playback in Firefox 3.6 with the Flash solution. However, the OGA format would be used in this case with the HTML solution.
请注意,{wmode:"window"} 选项设置为确保使用 Flash 解决方案在 Firefox 3.6 中播放。但是,在这种情况下,OGA 格式将与 HTML 解决方案一起使用。
回答by user1733849
You have an error in your code that is probably causing this behaviour:
您的代码中存在可能导致此行为的错误:
You have:
你有:
mp3: 'media/audio/04-Piste_4_1.mp3',
It should be
它应该是
mp3: 'media/audio/04-Piste_4_1.mp3'
So remove the comma.
所以去掉逗号。