jQuery jPlayer错误

4
我得到了以下错误信息。我正在使用HTML5。我尝试添加音频文件。错误如下:
无法获取属性'jPlayer'的值:对象为空或未定义
这个错误发生在标签上。
这是我的脚本代码:
 $(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>

我尝试使用 <audio> 标签,但需要在 IE8、IE9、Firefox 和 Chrome 中都能播放。我知道需要添加 .ogg 文件,但想先让它能正常工作,再添加其他文件类型。谢谢!


1
欢迎来到本站!为了获得最佳的JavaScript问题解答,我建议您创建一个JSfiddle。您可以在这里创建...http://jsfiddle.net/ - Alex Naspo
你尝试过调试它以查看它是否实际上找到了 $(“jpId”)对象吗? - Stephan
1个回答

1

我认为您应该先检查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>

你可以查看我编写的演示页面:
http://ohcool.org/sof/13628641.html

如果你想了解更多关于浏览器音乐文件类型支持的信息,请参阅:
http://html5doctor.com/native-audio-in-the-browser/

祝好运!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接