From 62ab565d1c772764c77dec0df75ce64b19c57119 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Wed, 18 Dec 2019 20:20:04 +0100 Subject: Add play/pause bezels to the video player --- client/src/assets/player/bezels/bezels-plugin.ts | 93 ++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 client/src/assets/player/bezels/bezels-plugin.ts (limited to 'client/src/assets/player/bezels/bezels-plugin.ts') diff --git a/client/src/assets/player/bezels/bezels-plugin.ts b/client/src/assets/player/bezels/bezels-plugin.ts new file mode 100644 index 000000000..4317d60f9 --- /dev/null +++ b/client/src/assets/player/bezels/bezels-plugin.ts @@ -0,0 +1,93 @@ +// @ts-ignore +import * as videojs from 'video.js' +import { VideoJSComponentInterface } from '../peertube-videojs-typings' + +function getPauseBezel () { + return ` +
+
+
+ + + + +
+
+
+ ` +} + +function getPlayBezel () { + return ` +
+
+
+ + + + +
+
+
+ ` +} + +// @ts-ignore-start +const Component = videojs.getComponent('Component') +class PauseBezel extends Component { + options_: any + container: HTMLBodyElement + + constructor (player: videojs.Player, options: any) { + super(player, options) + this.options_ = options + + player.on('pause', (_: any) => { + if (player.seeking()) return + this.container.innerHTML = getPauseBezel() + this.showBezel() + }) + + player.on('play', (_: any) => { + if (player.seeking()) return + this.container.innerHTML = getPlayBezel() + this.showBezel() + }) + } + + createEl () { + const container = super.createEl('div', { + className: 'vjs-bezels-content' + }) + this.container = container + container.style.display = 'none' + + return container + } + + showBezel () { + this.container.style.display = 'inherit' + setTimeout(() => { + this.container.style.display = 'none' + }, 500) // matching the animation duration + } +} +// @ts-ignore-end + +videojs.registerComponent('PauseBezel', PauseBezel) + +const Plugin: VideoJSComponentInterface = videojs.getPlugin('plugin') +class BezelsPlugin extends Plugin { + constructor (player: videojs.Player, options: any = {}) { + super(player, options) + + this.player.ready(() => { + player.addClass('vjs-bezels') + }) + + player.addChild('PauseBezel', options) + } +} + +videojs.registerPlugin('bezels', BezelsPlugin) +export { BezelsPlugin } -- cgit v1.2.3