说我有几秒钟的时间数组。
var points = [5, 30, 50];
因此,当初始化jw播放器时,我想读取此数组,然后在时间线上放置提示点[markers]。
一旦搜索栏到达提示点,我想调用一个执行某些操作的自定义函数。
Jw的文档很简单,但我发现了这个 - Adding chapter markers
我需要类似的东西,完全控制提示点。
有没有办法实现这个目标,还是应该使用自定义控制栏?
答案 0 :(得分:2)
我通过在某些点上暂停视频来实现相同的功能。暂停时,用户只能通过点击链接恢复视频(暂停时删除控件)。
我有以下HTML,其中放置了播放器和提示点HTML:
<div class="row">
<div class="col-xs-12 col-md-5">
<div id="myElement">Loading the player...</div>
</div>
<div class="col-xs-12 col-md-7">
<div id="on10seconds" class="hidden">
<p>Show after 10 seconds. <a href="#" class="positionInfoLink" data-position="10">Continue...</a></p>
</div>
<div id="on25seconds" class="hidden">
<p>Show after 25 seconds. <a href="#" class="positionInfoLink" data-position="25">Continue...</a></p>
</div>
<div id="on50seconds" class="hidden">
<p>Show after 50 seconds. <a href="#" class="positionInfoLink" data-position="50">Continue...</a></p>
</div>
</div>
</div>
以下JavaScript:
var positions = [10, 25, 50];
var positionsSeen = [];
var player = jwplayer("myElement").setup({
file: "/Content/videos/big_buck_bunny.mp4"
});
player.onTime(jwPlayerOnTime);
function jwPlayerOnTime(onTimeInfo) {
var currentPosition = onTimeInfo.position;
for (var i = 0; i < positions.length; i++) {
var position = positions[i];
var isPositionSeen = positionsSeen.indexOf(position) != -1;
// Within 2 seconds, so users can't skip to see the extra information displayed when pausing.
var isOnOrPastPosition = currentPosition > position && currentPosition <= position + 2;
if (isPositionSeen == false && isOnOrPastPosition) {
positionsSeen.push(position);
player.pause(true);
// Disable the controls, so the video can only be resumed with the custom controls.
player.setControls(false);
$("#on" + position + "seconds").removeClass("hidden");
}
}
}
$(document).ready(function () {
$(".positionInfoLink").on("click", function (e) {
e.preventDefault();
var position = $(this).data("position"); // 10, 25 or 50.
$(this).parent().addClass("hidden");
player.play(true);
// Enable the controls, so the video can be paused manually again.
player.setControls(true);
});
});