1
0
Fork 0

Cleaner videojs control bar implementation

This commit is contained in:
Chocobozzz 2018-03-01 19:02:51 +01:00
parent c7bfd4532e
commit 3ec8dc0962
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
6 changed files with 83 additions and 42 deletions

View File

@ -346,13 +346,35 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
peertube: { peertube: {
videoFiles: this.video.files, videoFiles: this.video.files,
playerElement: this.playerElement, playerElement: this.playerElement,
peerTubeLink: false,
videoViewUrl: this.videoService.getVideoViewUrl(this.video.uuid), videoViewUrl: this.videoService.getVideoViewUrl(this.video.uuid),
videoDuration: this.video.duration videoDuration: this.video.duration
}, },
hotkeys: { hotkeys: {
enableVolumeScroll: false enableVolumeScroll: false
} }
},
controlBar: {
children: [
'playToggle',
'currentTimeDisplay',
'timeDivider',
'durationDisplay',
'liveDisplay',
'flexibleWidthSpacer',
'progressControl',
'webTorrentButton',
'playbackRateMenuButton',
'muteToggle',
'volumeControl',
'resolutionMenuButton',
'fullscreenToggle'
]
} }
} }

View File

@ -22,7 +22,6 @@ interface VideoJSComponentInterface {
type PeertubePluginOptions = { type PeertubePluginOptions = {
videoFiles: VideoFile[] videoFiles: VideoFile[]
playerElement: HTMLVideoElement playerElement: HTMLVideoElement
peerTubeLink: boolean
videoViewUrl: string videoViewUrl: string
videoDuration: number videoDuration: number
} }
@ -120,7 +119,7 @@ class ResolutionMenuButton extends MenuButton {
MenuButton.registerComponent('ResolutionMenuButton', ResolutionMenuButton) MenuButton.registerComponent('ResolutionMenuButton', ResolutionMenuButton)
const Button: VideoJSComponentInterface = videojsUntyped.getComponent('Button') const Button: VideoJSComponentInterface = videojsUntyped.getComponent('Button')
class PeertubeLinkButton extends Button { class PeerTubeLinkButton extends Button {
createEl () { createEl () {
const link = document.createElement('a') const link = document.createElement('a')
@ -141,7 +140,7 @@ class PeertubeLinkButton extends Button {
this.parentNode.removeChild(this) this.parentNode.removeChild(this)
} }
} }
Button.registerComponent('PeerTubeLinkButton', PeertubeLinkButton) Button.registerComponent('PeerTubeLinkButton', PeerTubeLinkButton)
class WebTorrentButton extends Button { class WebTorrentButton extends Button {
createEl () { createEl () {
@ -392,20 +391,6 @@ class PeerTubePlugin extends Plugin {
} }
private initializePlayer (options: PeertubePluginOptions) { private initializePlayer (options: PeertubePluginOptions) {
const controlBar = this.player.controlBar
const menuButton = new ResolutionMenuButton(this.player, options)
const fullscreenElement = controlBar.fullscreenToggle.el()
controlBar.resolutionSwitcher = controlBar.el().insertBefore(menuButton.el(), fullscreenElement)
if (options.peerTubeLink === true) {
const peerTubeLinkButton = new PeertubeLinkButton(this.player)
controlBar.peerTubeLink = controlBar.el().insertBefore(peerTubeLinkButton.el(), fullscreenElement)
}
const webTorrentButton = new WebTorrentButton(this.player)
controlBar.webTorrent = controlBar.el().insertBefore(webTorrentButton.el(), controlBar.progressControl.el())
if (this.autoplay === true) { if (this.autoplay === true) {
this.updateVideoFile(undefined, () => this.player.play()) this.updateVideoFile(undefined, () => this.player.play())
} else { } else {

View File

@ -7,6 +7,15 @@
} }
} }
@mixin disable-outline {
outline: none;
&::-moz-focus-inner {
border: 0;
padding: 0
}
}
@mixin peertube-input-text($width) { @mixin peertube-input-text($width) {
display: inline-block; display: inline-block;
height: $button-height; height: $button-height;

View File

@ -1,4 +1,6 @@
@charset "utf-8";// Thanks: https://github.com/zanechua/videojs-sublime-inspired-skin @import '_variables';
@import '_mixins';
$primary-foreground-color: #fff; $primary-foreground-color: #fff;
$primary-background-color: #000; $primary-background-color: #000;
$font-size: 13px; $font-size: 13px;
@ -139,7 +141,8 @@ $control-bar-height: 34px;
} }
.vjs-play-control { .vjs-play-control {
outline: 0; @include disable-outline;
font-size: $font-size; font-size: $font-size;
padding: 0 17px; padding: 0 17px;
margin-right: 5px; margin-right: 5px;
@ -220,16 +223,24 @@ $control-bar-height: 34px;
.vjs-playback-rate { .vjs-playback-rate {
font-size: 10px; font-size: 10px;
margin-right: 50px; width: 37px !important;
.vjs-playback-rate-value { .vjs-playback-rate-value {
font-size: 13px; font-size: 13px;
line-height: $control-bar-height; line-height: $control-bar-height;
} }
.vjs-menu .vjs-menu-content {
width: 37px !important;
}
} }
.vjs-mute-control { .vjs-mute-control {
outline: 0; @include disable-outline;
line-height: $control-bar-height;
padding: 0;
width: 30px;
.vjs-icon-placeholder { .vjs-icon-placeholder {
display: inline-block; display: inline-block;
@ -250,12 +261,9 @@ $control-bar-height: 34px;
} }
} }
.vjs-volume-menu-button, .vjs-volume-control {
.vjs-volume-panel { width: 30px;
width: 6em; margin: 0;
position: absolute;
right: 0;
margin-right: 65px;
} }
.vjs-volume-bar { .vjs-volume-bar {
@ -313,8 +321,9 @@ $control-bar-height: 34px;
} }
.vjs-fullscreen-control { .vjs-fullscreen-control {
@include disable-outline;
width: 37px; width: 37px;
outline: 0;
.vjs-icon-placeholder { .vjs-icon-placeholder {
display: inline-block; display: inline-block;
@ -339,7 +348,7 @@ $control-bar-height: 34px;
line-height: $control-bar-height; line-height: $control-bar-height;
position: absolute; position: absolute;
top: 0; top: 0;
left: 4px; left: 0;
width: 100%; width: 100%;
height: 100%; height: 100%;
text-align: center; text-align: center;
@ -348,16 +357,16 @@ $control-bar-height: 34px;
} }
.vjs-resolution-button { .vjs-resolution-button {
outline: 0 !important; @include disable-outline;
} }
.vjs-menu { .vjs-menu {
top: 20px; top: 20px;
left: 0;
.vjs-menu-content { .vjs-menu-content {
width: 50px; width: 50px;
left: 50%; /* Center the menu, in it's parent */ bottom: 20px;
margin-left: -21px;
} }
li { li {

View File

@ -26,25 +26,21 @@ html, body {
} }
.vjs-peertube-link { .vjs-peertube-link {
@include disable-outline;
color: #fff; color: #fff;
text-decoration: none; text-decoration: none;
font-size: $font-size; font-size: $font-size;
line-height: $control-bar-height; line-height: $control-bar-height;
transition: all .4s; transition: all .4s;
font-weight: $font-semibold; font-weight: $font-semibold;
margin-right: 3px; padding-right: 5px;
padding: 0 5px;
} }
.vjs-peertube-link:hover { .vjs-peertube-link:hover {
text-shadow: 0 0 1em #fff; text-shadow: 0 0 1em #fff;
} }
// Fix volume panel because we added a new component (PeerTube link)
.vjs-volume-panel {
margin-right: 137px !important;
}
@media screen and (max-width: 350px) { @media screen and (max-width: 350px) {
.vjs-play-control { .vjs-play-control {
padding: 0 5px !important; padding: 0 5px !important;
@ -57,7 +53,6 @@ html, body {
.vjs-volume-panel { .vjs-volume-panel {
width: 26px !important; width: 26px !important;
margin-right: 140px !important;
} }
.vjs-peertube-link { .vjs-peertube-link {

View File

@ -31,13 +31,34 @@ loadVideoInfo(videoId)
peertube: { peertube: {
videoFiles: videoInfo.files, videoFiles: videoInfo.files,
playerElement: videoElement, playerElement: videoElement,
peerTubeLink: true,
videoViewUrl: getVideoUrl(videoId) + '/views', videoViewUrl: getVideoUrl(videoId) + '/views',
videoDuration: videoInfo.duration videoDuration: videoInfo.duration
}, },
hotkeys: { hotkeys: {
enableVolumeScroll: false enableVolumeScroll: false
} }
},
controlBar: {
children: [
'playToggle',
'currentTimeDisplay',
'timeDivider',
'durationDisplay',
'liveDisplay',
'flexibleWidthSpacer',
'progressControl',
'webTorrentButton',
'muteToggle',
'volumeControl',
'resolutionMenuButton',
'peerTubeLinkButton',
'fullscreenToggle'
]
} }
} }
videojs('video-container', videojsOptions, function () { videojs('video-container', videojsOptions, function () {