4

很抱歉问这个问题,因为它可能会在互联网上被问到几次,但没有一个建议的解决方案在我的网站上有效。

我正在尝试用广播流广告一个 jPlayer(作为大学项目的一部分)。

我将 jPlayer 的 JavaScript - jQuery 部分包含在一个名为 functions.js 的文件中:

// Reproductor de audio

$(document).ready(function(){

var stream = {
    title: "Postaway Radio",
    mp3: "http://listen.radionomy.com/1-PostawayRadio"
},
ready = false;

$("#jquery_jplayer_1").jPlayer({
    ready: function (event) {

        ready = true;
        $(this).jPlayer("setMedia", stream);
    },
    pause: function() {
        $(this).jPlayer("clearMedia");
    },
    error: function(event) {
        if(ready && event.jPlayer.error.type === $.jPlayer.error.URL_NOT_SET) {
            $(this).jPlayer("setMedia", stream).jPlayer("play");
        }
    },
    swfPath: "js",
    supplied: "mp3",
    preload: "none",
        wmode: "window"
});

});

这是文本的 HTML 部分:

            <div id="jquery_jplayer_1" class="jp-jplayer"></div>

        <div id="jp_container_1" class="jp-audio-stream">
            <div class="jp-type-single">
                <div class="jp-gui jp-interface">
                    <ul class="jp-controls">
                        <li><a href="javascript:;" class="jp-play" tabindex="1">play</a></li>
                        <li><a href="javascript:;" class="jp-pause" tabindex="1">pause</a></li>
                        <li><a href="javascript:;" class="jp-mute" tabindex="1" title="mute">mute</a></li>
                        <li><a href="javascript:;" class="jp-unmute" tabindex="1" title="unmute">unmute</a></li>
                        <li><a href="javascript:;" class="jp-volume-max" tabindex="1" title="max volume">max volume</a></li>
                    </ul>
                    <div class="jp-volume-bar">
                        <div class="jp-volume-bar-value"></div>
                    </div>
                </div>
                <div class="jp-title">
                    <ul>
                        <li>Postaway Radio</li>
                    </ul>
                </div>
                <div class="jp-no-solution">
                    <span>Update Required</span>
                    To play the media you will need to either update your browser to a recent version or update your <a href="http://get.adobe.com/flashplayer/" target="_blank">Flash plugin</a>.
                </div>
            </div>
        </div>

我试着玩它,它根本不起作用。我在 FireZilla 中收到此错误:

 TypeError: $("#jquery_jplayer_1").jPlayer is not a function

Chrome 控制台抛出此错误:

Uncaught TypeError: Object [object Object] has no method 'jPlayer' 
(anonymous function) functions.js:11
l jquery-1.8.3.min.js:2
c.fireWith jquery-1.8.3.min.js:2
v.extend.ready jquery-1.8.3.min.js:2
A

并将此行指示为问题:

`enter code here`$("#jquery_jplayer_1").jPlayer({

另一个是 jQuery。

但我无法找到问题所在。

我下载了一个 jPlayer 演示,代码很相似 - 和我的一样,但它在那里工作,而不是在我的网页中。还查看了开发人员(jPlayer)并没有找到解决方案。

Could anyone help me please?

Thanks for your help

4

2 回答 2

3

You probably didn't include jplayer library. Check demo again and see did you load jplayer js file properly. And check console in Google Chrome.

And which browser do you use. If the browser doesn't support html5, it will load flash player, but maybe the address for swf file is not good. That's set in this parameter swfPath: "js"

Try with this:

$player = $("#jquery_jplayer_1")
jPlayer_method = $player.jPlayer
$player.jPlayer({
    ready: function () {
           jPlayer_method.call( $player, "setMedia", {
                                       [...same as before...]
于 2012-12-27T13:39:57.477 回答
0

If somehow you are still using it in or after 2018 like me, make sure jquery library is loaded first then jplayer.min.js file.

于 2018-09-01T19:43:42.273 回答