jPlayer多个流实例

时间:2013-07-27 12:11:27

标签: jplayer

我需要使用this播放器与jPlayer一起使用多个流实例。默认情况下它不是这样我尝试进行多次更改但仍无法使其正常工作。第一个玩家工作,但它一起播放所有其他流,第二个玩家根本无法触发。任何的想法?我的代码如下:

SCRIPT

<script type="text/javascript">
    //<![CDATA[
    jQuery(document).ready(function(){

        var stream = {
            title: "ABC Jazz",
            mp3: "http://listen.radionomy.com/abc-jazz"
        },
        ready = false;

        jQuery("#jquery_jplayer_11").jPlayer({
            ready: function (event) {
                ready = true;
                jQuery(this).jPlayer("setMedia", stream);
            },
            pause: function() {
                jQuery(this).jPlayer("clearMedia");
            },
            error: function(event) {
                if(ready && event.jPlayer.error.type === jQuery.jPlayer.error.URL_NOT_SET) {
                    // Setup the media stream again and play it.
                    jQuery(this).jPlayer("setMedia", stream).jPlayer("play");
                }
            },
            swfPath: "js",
            supplied: "mp3",
            preload: "none",
            wmode: "window",
            keyEnabled: true
        });

        var stream2 = {
            title: "Second",
            mp3: "http://stream.x-x-x-x.com:1234/stream"
        },
        ready = false;

        jQuery("#jquery_jplayer_12").jPlayer({
            ready: function (event) {
                ready = true;
                jQuery(this).jPlayer("setMedia", stream2);
            },
            pause: function() {
                jQuery(this).jPlayer("clearMedia");
            },
            error: function(event) {
                if(ready && event.jPlayer.error.type === jQuery.jPlayer.error.URL_NOT_SET) {
                    // Setup the media stream again and play it.
                    jQuery(this).jPlayer("setMedia", stream2).jPlayer("play");
                }
            },
            swfPath: "js",
            supplied: "mp3",
            preload: "none",
            wmode: "window",
            keyEnabled: true
        });
    });
    //]]>
</script>

HTML

<div id="jquery_jplayer_11" class="jp-jplayer" style="width: 0px; height: 0px;">
    <img id="jp_poster_0" style="width: 0px; height: 0px; display: none;">
    <audio id="jp_audio_0" preload="none"></audio>
</div>

<div id="jquery_jplayer_12" class="jp-jplayer" style="width: 0px; height: 0px;">
    <img id="jp_poster_0" style="width: 0px; height: 0px; display: none;">
    <audio id="jp_audio_0" preload="none"></audio>
</div>

<div id="jp_container_1" class="jp-audio-stream">
                <div class="jp-gui jp-interface">
                    <ul class="jp-controls">
                        <li class="pp-li"><a href="javascript:;" class="jp-play" tabindex="1" style="">play</a></li>
                        <li class="pp-li"><a href="javascript:;" class="jp-pause" tabindex="1" style="display: none;">pause</a></li>
                        <li class="mu-li"><a href="javascript:;" class="jp-mute" tabindex="1" title="mute" style="">mute</a></li>
                        <li class="mu-li"><a href="javascript:;" class="jp-unmute" tabindex="1" title="unmute" style="display: none;">unmute</a></li>
                        <li class="vo-li"><a href="javascript:;" class="jp-volume-max" tabindex="1" title="max volume" style="">max volume</a></li>
                    </ul>
                    <div class="jp-volume-bar" style="">
                        <div class="jp-volume-bar-value" style="width: 80%;"></div>
                    </div>
                </div>
            </div>

<div id="jp_container_2" class="jp-audio-stream">
                <div class="jp-gui jp-interface">
                    <ul class="jp-controls">
                        <li class="pp-li"><a href="javascript:;" class="jp-play" tabindex="1" style="">play</a></li>
                        <li class="pp-li"><a href="javascript:;" class="jp-pause" tabindex="1" style="display: none;">pause</a></li>
                        <li class="mu-li"><a href="javascript:;" class="jp-mute" tabindex="1" title="mute" style="">mute</a></li>
                        <li class="mu-li"><a href="javascript:;" class="jp-unmute" tabindex="1" title="unmute" style="display: none;">unmute</a></li>
                        <li class="vo-li"><a href="javascript:;" class="jp-volume-max" tabindex="1" title="max volume" style="">max volume</a></li>
                    </ul>
                    <div class="jp-volume-bar" style="">
                        <div class="jp-volume-bar-value" style="width: 80%;"></div>
                    </div>
                </div>
            </div>

1 个答案:

答案 0 :(得分:0)

组    cssSelectorAncestor:&#34; #jp_container_2&#34;    cssSelectorAncestor:&#34; #jp_container_1&#34;

对于所有玩家和播放列表选项之后(这意味着在代码的底部)

 $("#jplayer_inspector_1").jPlayerInspector({jPlayer:$("#jquery_jplayer_1")});
 $("#jplayer_inspector_2").jPlayerInspector({jPlayer:$("#jquery_jplayer_2")});

这样对所有玩家来说它会起作用,如果不是意味着将所有代码放在这里,那么我将纠正错误