Add play/pause bezels to the video player

This commit is contained in:
Rigel Kent 2019-12-18 20:20:04 +01:00
parent 2a5518a667
commit 62ab565d1c
No known key found for this signature in database
GPG Key ID: 5E53E96A494E452F
6 changed files with 141 additions and 2 deletions

View File

@ -469,6 +469,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
this.zone.runOutsideAngular(async () => {
this.player = await PeertubePlayerManager.initialize(playerMode, playerOptions, player => this.player = player)
this.player.focus()
this.player.bezels()
this.player.on('customError', ({ err }: { err: any }) => this.handleError(err))

View File

@ -0,0 +1,93 @@
// @ts-ignore
import * as videojs from 'video.js'
import { VideoJSComponentInterface } from '../peertube-videojs-typings'
function getPauseBezel () {
return `
<div class="vjs-bezels-pause">
<div class="vjs-bezel" role="status" aria-label="Pause">
<div class="vjs-bezel-icon">
<svg height="100%" version="1.1" viewBox="0 0 36 36" width="100%">
<use class="vjs-svg-shadow" xlink:href="#vjs-id-1"></use>
<path class="vjs-svg-fill" d="M 12,26 16,26 16,10 12,10 z M 21,26 25,26 25,10 21,10 z" id="vjs-id-1"></path>
</svg>
</div>
</div>
</div>
`
}
function getPlayBezel () {
return `
<div class="vjs-bezels-play">
<div class="vjs-bezel" role="status" aria-label="Play">
<div class="vjs-bezel-icon">
<svg height="100%" version="1.1" viewBox="0 0 36 36" width="100%">
<use class="vjs-svg-shadow" xlink:href="#vjs-id-2"></use>
<path class="vjs-svg-fill" d="M 12,26 18.5,22 18.5,14 12,10 z M 18.5,22 25,18 25,18 18.5,14 z" id="ytp-id-2"></path>
</svg>
</div>
</div>
</div>
`
}
// @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 }

View File

@ -6,6 +6,7 @@ import 'videojs-dock'
import 'videojs-contextmenu-ui'
import 'videojs-contrib-quality-levels'
import './upnext/upnext-plugin'
import './bezels/bezels-plugin'
import './peertube-plugin'
import './videojs-components/peertube-link-button'
import './videojs-components/resolution-menu-button'

View File

@ -0,0 +1,42 @@
@keyframes bezels-fadeout {
from {
opacity: 1;
}
to {
opacity: 0;
transform: scale(2);
}
}
.vjs-bezel {
position: absolute;
left: 50%;
top: 50%;
width: 52px;
height: 52px;
z-index: 19;
margin-left: -26px;
margin-top: -26px;
background: rgba(0,0,0,.5);
border-radius: 26px;
animation: bezels-fadeout .5s linear 1 normal forwards;
pointer-events: none;
}
.vjs-bezel-icon {
width: 36px;
height: 36px;
margin: 8px;
svg .vjs-svg-fill {
fill: #fff;
}
}
.video-js {
.vjs-bezel-content {
}
}

View File

@ -3,4 +3,5 @@
@import './context-menu';
@import './settings-menu';
@import './spinner';
@import './upnext';
@import './upnext';
@import './bezels.scss';

View File

@ -95,8 +95,9 @@ $browser-context: 16;
width: 98px;
height: 98px;
margin: -49px 0 0 -49px;
transition: stroke-dasharray 0.1s cubic-bezier(0.4,0,1,1);
cursor: pointer;
@include transition(stroke-dasharray 0.1s cubic-bezier(0.4,0,1,1));
}
}