2016-03-07 323 views
1

我们使用的是JPlayer 2.9.2和一个非常基本的原型(请参阅下面的代码片段)。为什么jPlayer在轨道播放结束时触发暂停事件

当轨道结束时,在Chrome中触发'pause'事件,然后触发'ended'事件,在Firefox中,只有'pause'事件被触发。

任何人都可以解释为什么这种情况?

我们刺激了这个原型,因为在我们的生产代码中,我们看到了类似混淆的行为。如'暂停'在手机上发射,'结束'在台式机上发射。

<head> 
 
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script> 
 
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jplayer/2.9.2/jplayer/jquery.jplayer.js"></script> 
 
<script type="text/javascript"> 
 
    $(document).ready(function(){ 
 
     $("#jquery_jplayer_1").jPlayer({ 
 
     ready: function() { 
 
      $(this).jPlayer("setMedia", { 
 
      title: "Bubble", 
 
      m4a: "http://www.jplayer.org/audio/m4a/Miaow-07-Bubble.m4a", 
 
      oga: "http://www.jplayer.org/audio/ogg/Miaow-07-Bubble.ogg" 
 
      }); 
 
     }, 
 
     cssSelectorAncestor: "#jp_container_1", 
 
     swfPath: "/js", 
 
     supplied: "m4a, oga", 
 
     useStateClassSkin: true, 
 
     autoBlur: false, 
 
     smoothPlayBar: true, 
 
     keyEnabled: true, 
 
     remainingDuration: true, 
 
     toggleDuration: true, 
 
\t \t ended : function(){ 
 
\t \t \t var sam = 1; 
 
\t \t }, 
 
\t \t pause : function(){ 
 
\t \t \t var sam = 2; 
 
\t \t }, 
 
\t \t 
 
     }); 
 
    }); 
 
    </script> 
 
</head> 
 
<body> 
 
<div id="jquery_jplayer_1" class="jp-jplayer"></div> 
 
<div id="jp_container_1" class="jp-audio" role="application" aria-label="media player"> 
 
    <div class="jp-type-single"> 
 
    <div class="jp-gui jp-interface"> 
 
     <div class="jp-volume-controls"> 
 
     <button class="jp-mute" role="button" tabindex="0">mute</button> 
 
     <button class="jp-volume-max" role="button" tabindex="0">max volume</button> 
 
     <div class="jp-volume-bar"> 
 
      <div class="jp-volume-bar-value"></div> 
 
     </div> 
 
     </div> 
 
     <div class="jp-controls-holder"> 
 
     <div class="jp-controls"> 
 
      <button class="jp-play" role="button" tabindex="0">play</button> 
 
      <button class="jp-stop" role="button" tabindex="0">stop</button> 
 
     </div> 
 
     <div class="jp-progress"> 
 
      <div class="jp-seek-bar"> 
 
      <div class="jp-play-bar"></div> 
 
      </div> 
 
     </div> 
 
     <div class="jp-current-time" role="timer" aria-label="time">&nbsp;</div> 
 
     <div class="jp-duration" role="timer" aria-label="duration">&nbsp;</div> 
 
     <div class="jp-toggles"> 
 
      <button class="jp-repeat" role="button" tabindex="0">repeat</button> 
 
     </div> 
 
     </div> 
 
    </div> 
 
    <div class="jp-details"> 
 
     <div class="jp-title" aria-label="title">&nbsp;</div> 
 
    </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> 
 
</body>

+0

嗨丹。你有没有想过这个? –

+0

不,我在GitHub上也发现了一个bug。思考? – Dan

+0

不是我的头顶。根据源代码,FireFox也应该解雇'Ended'。我会在有空的时候再测试它。你能链接github链接吗? 暂停事件被触发,因为否则点击进度条将从该点播放,当它不应该时,因为它停止播放(取自src代码中的注释)。所以这应该发生。 –

回答

0

我只是测试它,它的工作对我来说。你使用哪个Firefox版本?

  • Chrome:已暂停 - >已结束。
  • FireFox:已结束 - >已暂停。

http://jsfiddle.net/chq6uu16/13/

的源代码jPlayer:

mediaElement.addEventListener("ended", function() { 
       if (entity.gate) { 
        // Order of the next few commands are important. Change the time and then pause. 
        // Solves a bug in Firefox, where issuing pause 1st causes the media to play from the start. ie., The pause is ignored. 
        if (!$.jPlayer.browser.webkit) { // Chrome crashes if you do this in conjunction with a setMedia command in an ended event handler. ie., The playlist demo. 
         self.htmlElement.media.currentTime = 0; // Safari does not care about this command. ie., It works with or without this line. (Both Safari and Chrome are Webkit.) 
        } 
        self.htmlElement.media.pause(); // Pause otherwise a click on the progress bar will play from that point, when it shouldn't, since it stopped playback. 
        self._updateButtons(false); 
        self._getHtmlStatus(mediaElement, true); // With override true. Otherwise Chrome leaves progress at full. 
        self._updateInterface(); 
        self._trigger($.jPlayer.event.ended); 
       } 
      }, false); 

它看起来像不同的排序,其中首先被解雇是必要的浏览器修复。

此外,我已经听过那个'Miaow-07-Bubble'很多次了,我现在真的很喜欢它:P。