您好我是HTML5开发的新手。我目前正在使用video-js进行学校项目。该项目要求视频播放器滑动条中的动态标记指示特定位置,以便视频查看器知道在哪里跳转。我不确定以下问题:
感谢您的帮助。
答案 0 :(得分:0)
用于在控制栏中创建标记的示例插件:
/**
* Utility function to find the percent a given time represents in
* the overall duration.
*/
var getPercent = function(value, total) {
var raw = value * 1.0 / total;
var bounded = Math.min(1, Math.max(0, raw));
return Math.round(bounded * 100, 2);
};
/**
* Draws a single highlighted section on the control bar. Assumes all
* sections require a start value, but not an end value (defaults to a
* 1 second duration).
*/
var drawSection = function(player, section, duration) {
if (!section.start) return;
if (!section.end) section.end = section.start + 1;
var seekBar = vid.controlBar.progressControl.seekBar;
var sectionDiv = seekBar.createEl('div');
// You'd probably want to have a css class for these styles.
sectionDiv.style.backgroundColor = 'yellow';
sectionDiv.style.position = 'absolute';
sectionDiv.style.height = '100%';
var startPercent = getPercent(section.start, duration);
var endPercent = getPercent(section.end, duration);
sectionDiv.style.left = startPercent + '%';
sectionDiv.style.width = (endPercent - startPercent) + '%';
var seekHandle = seekBar.seekHandle;
seekBar.el().insertBefore(sectionDiv, seekHandle.el());
};
var drawSections = function(player, sections) {
var duration = player.duration();
if (duration === undefined || isNaN(duration)) return;
for (var i = 0, l = sections.length; i < l; i++) {
drawSection(player, sections[i], duration);
}
};
var highlightedSectionsPlugin = function(options) {
var player = this;
player.on('durationchange',
function() { drawSections(player, options.sections); });
};
videojs.plugin('highlightedSectionsPlugin', highlightedSectionsPlugin);
var vid = videojs("video", {
plugins : {
highlightedSectionsPlugin : {
sections : [ {start:10, end:20}, {start:25, end:30}, {start: 40} ]
}
}
});