2016-03-07 326 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。