5

如果有人以前使用过 jplayer,我需要这个问题的帮助。

我有多个 jplayers,每个播放器都应该播放自己的音频文件。但它不是这样做的,如果我播放一个 jplayer,那么所有的 jplayer 都会播放,都播放来自所选 jplayer 的那个音频文件。事实上,如果我在一个 jplayer 中使用一个控件,它也会控制所有其他 jplayer。

所以我正在尝试实现一个多实例 jplayers,其信息来自:

http://www.jplayer.org/latest/demo-03/

但我真的很难实现这一点,所以我的问题是有人可以帮我完成这个实现,以便 jplayer 可以正常工作,而 jplayer 只控制自己的播放器而不影响其他 jplayer?

以下是我目前拥有的javascript代码(查看源代码):

<script type="text/javascript">   
    $(document).ready(function(){
  $("#jquery_jplayer_1-72-0").jPlayer({
    ready: function () {
      $(this).jPlayer("setMedia", {
        mp3: "AudioFiles/Kalimba.mp3"
      });
    },
    play: function() { // To avoid both jPlayers playing together.
      $(this).jPlayer("pauseOthers");
   },
    solution:"flash,html",
    swfPath: "jquery",
    supplied: "mp3"
  });
}); 
</script>

更新:

实际代码:

如果没有音频文件,则为每个音频文件显示一个空白,否则,显示一个音频播放器。我也包含了 html 控件,不确定是否需要,但发布它以防万一

        //start:procedure audio
        $aud_result = '';
        if(empty($arrAudioFile[$key])){
          $aud_result = '&nbsp;';
        }else{

$j = 0;
foreach ($arrAudioFile[$key] as $a) { 

        $info = pathinfo('AudioFiles/'.$a); 
?>

<script type="text/javascript">   
    $(document).ready(function(){

$("#jquery_jplayer_1-<?php echo $key.'-'.$j; ?>").jPlayer({
    ready: function () {
      $(this).jPlayer("setMedia", {
        <?php echo $info['extension'];?>: "<?php echo "AudioFiles/".$a; ?>"
      });
      $(this).bind($.jPlayer.event.play, function() { 
          $(this).jPlayer("pauseOthers");
        });
    },
    solution:"flash,html",
    swfPath: "jquery",
    supplied: "<?php echo $info['extension'];?>"
});
}); 
</script>
  <div id="jquery_jplayer_1-<?php echo $key.'-'.$j; ?>" class="jp-jplayer"></div>
  <div id="jp_container_1" class="jp-audio">
    <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-stop" tabindex="1">stop</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-progress">
          <div class="jp-seek-bar">
            <div class="jp-play-bar"></div>
          </div>
        </div>
        <div class="jp-volume-bar">
          <div class="jp-volume-bar-value"></div>
        </div>
        <div class="jp-time-holder">
          <div class="jp-current-time"></div>
          <div class="jp-duration"></div>
          <ul class="jp-toggles">
            <li><a href="javascript:;" class="jp-repeat" tabindex="1" title="repeat">repeat</a></li>
            <li><a href="javascript:;" class="jp-repeat-off" tabindex="1" title="repeat off">repeat off</a></li>
          </ul>
        </div>
      </div>
    </div>
  </div>
<?php $j++; 
}

}
//end:procedure audio
?>
4

2 回答 2

9

您可以像这样创建一个function并传递参数 ( file and player id) 以在同一页面上创建不同的播放器,而不会产生任何冲突:

function js_audioPlayer(file,location) {
    jQuery("#jquery_jplayer_" + location).jPlayer( {
        ready: function () {
          jQuery(this).jPlayer("setMedia", {
        mp3: file
          });
        },
        cssSelectorAncestor: "#jp_interface_" + location,
        swfPath: "/swf"
    });
        return;
}

在这个例子中,一个文件和位置变量被传递到一个包装函数中,然后构造播放器。

然后js_audioPlayer()根据需要多次运行 javascript 函数:

js_audioPlayer('file1.mp3',1); //Player 1
js_audioPlayer('file2.mp3',2); //Player 2
js_audioPlayer('file3.mp3',3); //Player 3

创建带有 ID 的 Player DIV:

jquery_jplayer_1 
jquery_jplayer_2
jquery_jplayer_3

和带有 ID 的接口 DIV:

jp_interface_1
jp_interface_2
jp_interface_3

希望这可以帮助。

更多详情http ://www.nightbluefruit.com/blog/2011/08/multiple-jplayers-on-the-same-page/

于 2013-02-09T05:16:42.427 回答
0

这是使用 jplayer 的多个音频播放器实例的代码。以下代码对我有用。希望这对任何人都有帮助。

$(document).ready(function(){
    /*---Create a jplayer instance on click on the play image---*/

    $(".audio").click(function() {
       $.jPlayer.pause();
       var record_id = this.id;
       var path = 'path for the audio file';
       $("#jquery_jplayer_"+record_id).jPlayer({
            ready: function (event) {
                $(this).jPlayer("setMedia", {
                    title: "Bubble",
                    oga: path,
                });
            },
            cssSelectorAncestor: "#jp_container_"+record_id,
            supplied: "oga",
            wmode: "window",
            errorAlerts: true,
            consoleAlerts: true,
            warningAlerts: true,
            useStateClassSkin: true,
            autoBlur: false,
            smoothPlayBar: true,
            keyEnabled: true,
            remainingDuration: true,
            toggleDuration: true
        });
    });
});
于 2015-06-08T06:56:45.273 回答