Выполнено с помощью jwplayer 5.
Вы должны обработать события onBeforePlay
, onPause
, onComplete
и onReady
проигрывателя.
Плеер встроен с использованием jwplayer.setup внутри этого HTML.
<div class="video_unique_id">
<div id="container_unique_id">
</div>
</div>
Это выдержка из класса обработки jwplayer, который я использую:
var _self = this;
var _timeout = null;
var _player = jwplayer('container_unique_id');
// Set up the jwplayer (e.g. controlbar.position":"bottom")
_player.setup( ... );
/**
* Fired when the player has initialized and is ready for playback.
*/
_player.onReady(
function() {
// Show controlbar while moving the mouse around
$('.video_unique_id').mousemove(function() {
if (_player.getState() === 'PLAYING') {
_self.showControls();
if (_timeout) {
window.clearTimeout(_timeout);
}
// Start timeout to hide controls but
// only if playing a video
_timeout = window.setTimeout(function() {
if (_player.getState() === 'PLAYING') {
_self.hideControls();
}
}, 1500);
}
});
// Show controlbar while entering player container
$('.video_unique_id').mouseenter(function() {
if (_player.getState() === 'PLAYING') {
_self.showControls();
}
});
// Hide controlbar while leaving player container
$('.video_unique_id').mouseleave(function() {
if (_player.getState() === 'PLAYING') {
_self.hideControls();
}
});
}
);
/**
* Fired just before the player begins playing. Unlike the onPlay
* and onBuffer events, the player will not have begun playing or
* buffering when onBeforePlay is triggered. This event can be used
* to prevent playback from occurring by calling the stop() function.
*/
_player.onBeforePlay(
function() {
_self.hideControls();
}
);
/**
* Fired when the player enters the PAUSED state.
*
* @param {Array} event Array with old and new player state
*/
_player.onPause(
function(event) {
_self.showControls();
}
);
/**
* Fired when the player has finished playing the current media.
*/
_player.onComplete(
function() {
_self.showControls();
}
);
/**
* Show all controls.
*
* @return void
*/
this.showControls = function()
{
// Show control bar
_player.getPlugin('controlbar').show();
};
/**
* Hide all controls.
*
* @return void
*/
this.hideControls = function()
{
// Hide control bar
_player.getPlugin('controlbar').hide();
};