我收到以下错误。我正在使用 HTML5。我正在尝试添加音频文件。错误是:
无法获取属性“jPlayer”的值:对象为 null 或未定义
它在
上抛出一个错误这是我的脚本:
$(document).ready(function () {
$("#jpId").jPlayer({
ready: function () {
this.element.jPlayer("setFile", "../179_short_all-the-family-together_0033.mp3"); // Defines the counterpart mp3 and ogg files
},
oggSupport: true,
});
});
我的 HTML5 div:
<div id="jpId">
</div>
我试过使用标签,但我需要音乐在 IE8、IE9、Firefox、Chrome 中工作。我知道我需要添加 .ogg 文件,但希望在添加其他文件类型之前让它工作。谢谢!
最佳答案
我认为您应该先查看 jPlayer 演示代码和文档。 (http://www.jplayer.org)
而且我认为您必须像这样更改您的 js:
$('#jpId').jPlayer({
ready: function () {
$(this).jPlayer("setMedia", { //use "setMedia". "setFile" doesn't in DevGuide
mp3: "class.mp3", //set mp3 media path, also can use url
oga: "pop.ogg" // set ogg media path, pay attention to use "oga" not "ogg"
});
},
preload: "none",
supplied: "oga, mp3", //test set the order of media you want to use
cssSelectorAncestor: "#jpContainer" // in order to add the controller
});
HTML代码建议:
<div id="jpId"></div>
<div id="jpContainer">
<a href="javascript:;" class="jp-play" tabindex="1">play</a>
<a href="javascript:;" class="jp-pause" tabindex="1">pause</a>
</div>
你可以查看我写的DEMO页面:
http://ohcool.org/sof/13628641.html
如果您想了解更多关于浏览器音乐文件类型支持的信息,请查看:
http://html5doctor.com/native-audio-in-the-browser/
祝你好运!
关于javascript - jQuery jPlayer 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13628641/