javascript - jQuery jPlayer 错误

标签 javascript jquery html

我收到以下错误。我正在使用 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/

相关文章:

javascript - 从 jquery 到 javascript 的转换问题

javascript - JQuery - 在 window.location 之后使用 $(document).ready()

复选框上的 Javascript 克隆此 div,未选中时删除此 div

html - 无法从 css 中的相对/绝对定位获得所需的输出

java - SendRedirect 与 Java Servlet 中的转发用例

javascript - JQuery:使用可拖动 div 进行 z 索引排序

javascript - 类型错误 : Cannot read property 'avatar' of null

javascript - 如何解决 TSX 中的类型 'void' 无法分配给类型 'ReactNode' 问题

javascript - 更新面板 AJAX asp.net 后运行脚本

jQuery.animate() 似乎将持续时间参数作为延迟