gpt4 book ai didi

javascript - 为什么 jPlayer 在轨道播放结束时触发暂停事件

转载 作者:行者123 更新时间:2023-11-28 06:17:18 29 4
gpt4 key购买 nike

我们使用的是 JPlayer 2.9.2,具有非常基本的原型(prototype)(请参阅下面的代码片段)。

当轨道结束时,将触发“暂停”事件,然后在 Chrome 中触发“结束”事件,而在 Firefox 中,仅触发“暂停”事件。

谁能解释一下为什么会这样?

我们增加了这个原型(prototype),因为在我们的生产代码中我们看到了类似的令人困惑的行为。例如“暂停”在移动设备上触发,“结束”在桌面设备上触发。

<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,
ended : function(){
var sam = 1;
},
pause : function(){
var sam = 2;
},

});
});
</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>

最佳答案

我刚刚测试了它,它对我有用。您使用的是哪个版本的 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。

关于javascript - 为什么 jPlayer 在轨道播放结束时触发暂停事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35848855/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com