Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Better video player responsive

Chocobozzzcd9b8c2cc88a
diff --git a/client/src/assets/player/peertube-player.ts b/client/src/assets/player/peertube-player.ts
index 084ef965d0..4e16a7b9cd 100644
--- a/client/src/assets/player/peertube-player.ts
+++ b/client/src/assets/player/peertube-player.ts
@@ -124,6 +124,7 @@ export class PeerTubePlayer {
setPoster (url: string) {
this.player?.poster(url)
+ this.options.playerElement().poster = ''
}
enable () {
diff --git a/client/src/assets/player/shared/peertube/peertube-plugin.ts b/client/src/assets/player/shared/peertube/peertube-plugin.ts
index a01d7e08c1..d9aeadb67e 100644
--- a/client/src/assets/player/shared/peertube/peertube-plugin.ts
+++ b/client/src/assets/player/shared/peertube/peertube-plugin.ts
@@ -47,6 +47,8 @@ class PeerTubePlugin extends Plugin {
private stopTimeHandler: (...args: any[]) => void
+ private resizeObserver: ResizeObserver
+
constructor (player: videojs.Player, private readonly options: PeerTubePluginOptions) {
super(player)
@@ -122,9 +124,24 @@ class PeerTubePlugin extends Plugin {
this.hideFatalError()
})
+
+ this.updatePlayerSizeClasses()
+
+ if (typeof ResizeObserver !== 'undefined') {
+ this.resizeObserver = new ResizeObserver(() => {
+ this.updatePlayerSizeClasses()
+ })
+
+ this.resizeObserver.observe(this.player.el())
+ }
})
this.player.on('resolution-change', (_: any, { resolution }: { resolution: number }) => {
+ if (this.player.paused()) {
+ this.player.on('play', () => this.adaptPosterForAudioOnly(resolution))
+ return
+ }
+
this.adaptPosterForAudioOnly(resolution)
})
@@ -133,6 +150,7 @@ class PeerTubePlugin extends Plugin {
dispose () {
if (this.videoViewInterval) clearInterval(this.videoViewInterval)
+ if (this.resizeObserver) this.resizeObserver.disconnect()
super.dispose()
}
@@ -233,20 +251,22 @@ class PeerTubePlugin extends Plugin {
const defaultRatio = getComputedStyle(this.player.el()).getPropertyValue(this.options.autoPlayerRatio.cssRatioVariable)
- const updateFromOptions = () => {
+ const tryToUpdateRatioFromOptions = () => {
if (!this.options.videoRatio()) return
this.adaptPlayerFromRatio({ ratio: this.options.videoRatio(), defaultRatio })
+ this.updatePlayerSizeClasses()
}
- updateFromOptions()
+ tryToUpdateRatioFromOptions()
- this.player.on('video-change', () => updateFromOptions())
+ this.player.on('video-change', () => tryToUpdateRatioFromOptions())
this.player.on('video-ratio-changed', (_event, data: { ratio: number }) => {
if (this.options.videoRatio()) return
this.adaptPlayerFromRatio({ ratio: data.ratio, defaultRatio })
+ this.updatePlayerSizeClasses()
})
}
@@ -376,6 +396,26 @@ class PeerTubePlugin extends Plugin {
// ---------------------------------------------------------------------------
+ private updatePlayerSizeClasses () {
+ requestAnimationFrame(() => {
+ debugLogger('Updating player size classes')
+
+ const width = this.player.currentWidth()
+
+ const breakpoints = [ 350, 570, 750 ]
+
+ for (const breakpoint of breakpoints) {
+ if (width <= breakpoint) {
+ this.player.addClass('vjs-size-' + breakpoint)
+ } else {
+ this.player.removeClass('vjs-size-' + breakpoint)
+ }
+ }
+ })
+ }
+
+ // ---------------------------------------------------------------------------
+
private listenFullScreenChange () {
this.player.on('fullscreenchange', () => {
if (this.player.isFullscreen()) this.player.focus()
diff --git a/client/src/sass/player/_player-variables.scss b/client/src/sass/player/_player-variables.scss
index 25d734e747..ae048af07e 100644
--- a/client/src/sass/player/_player-variables.scss
+++ b/client/src/sass/player/_player-variables.scss
@@ -29,8 +29,4 @@ $dock-padding: 20px;
$first-control-bar-element-margin-left: 10px;
$first-control-bar-element-margin-left-small-width: 5px;
-$screen-width-750: 750px;
-$screen-width-570: 570px;
-$screen-width-350: 350px;
-
$assets-path: '../../assets/' !default;
diff --git a/client/src/sass/player/control-bar.scss b/client/src/sass/player/control-bar.scss
index 86f51849f0..cbf75e1c00 100644
--- a/client/src/sass/player/control-bar.scss
+++ b/client/src/sass/player/control-bar.scss
@@ -462,94 +462,98 @@
}
}
}
+}
- @media screen and (max-width: $screen-width-750) {
- .vjs-theater-control {
- display: none;
- }
+.vjs-marker {
+ position: absolute;
+ width: 3px;
+ opacity: .5;
+ background-color: #000;
+ height: 100%;
+ top: 0;
+}
- .vjs-peertube {
- .icon,
- .download-speed-text,
- .upload-speed-text {
- display: none !important;
- }
- }
+.vjs-peertube-skin.vjs-has-captions .vjs-caption-toggle-control {
+ display: block !important;
+}
+
+// ---------------------------------------------------------------------------
+// Custom media queries
+// ---------------------------------------------------------------------------
+
+.video-js.vjs-peertube-skin.vjs-size-750 .vjs-control-bar {
+ .vjs-theater-control {
+ display: none;
}
- @media screen and (max-width: $screen-width-570) {
- .vjs-volume-control {
- display: none;
+ .vjs-peertube {
+ .icon,
+ .download-speed-text,
+ .upload-speed-text {
+ display: none !important;
}
+ }
+}
- .vjs-mute-control {
- @include margin(0, 5px, 0, 5px);
- }
+.video-js.vjs-peertube-skin.vjs-size-570 .vjs-control-bar {
+ .vjs-volume-control {
+ display: none;
+ }
- .vjs-peertube {
- padding: 0 !important;
+ .vjs-mute-control {
+ @include margin(0, 5px, 0, 5px);
+ }
- .vjs-peertube-displayed {
- display: none !important;
- }
- }
+ .vjs-peertube {
+ padding: 0 !important;
- .vjs-peertube-link {
- max-width: 100px;
+ .vjs-peertube-displayed {
+ display: none !important;
}
+ }
- &.vjs-live {
- .vjs-duration {
- display: none !important;
- }
-
- .vjs-peertube {
- display: none !important;
- }
- }
+ .vjs-peertube-link {
+ max-width: 100px;
}
- @media screen and (max-width: $screen-width-350) {
- .vjs-next-video,
- .vjs-previous-video {
+ &.vjs-live {
+ .vjs-duration {
display: none !important;
}
- .vjs-peertube-link {
- padding: 0 !important;
- }
-
- > button:first-child {
- @include margin-left($first-control-bar-element-margin-left-small-width);
+ .vjs-peertube {
+ display: none !important;
}
+ }
+}
- > button:last-child {
- @include margin-right($first-control-bar-element-margin-left-small-width);
- }
+.video-js.vjs-peertube-skin.vjs-size-350 .vjs-control-bar {
+ .vjs-next-video,
+ .vjs-previous-video {
+ display: none !important;
+ }
- .vjs-play-control {
- @include margin-left(0);
+ .vjs-peertube-link {
+ padding: 0 !important;
+ }
- width: 30px;
- }
+ > button:first-child {
+ @include margin-left($first-control-bar-element-margin-left-small-width);
+ }
- &.vjs-live {
- .vjs-current-time {
- display: none !important;
- }
- }
+ > button:last-child {
+ @include margin-right($first-control-bar-element-margin-left-small-width);
}
-}
-.vjs-marker {
- position: absolute;
- width: 3px;
- opacity: .5;
- background-color: #000;
- height: 100%;
- top: 0;
-}
+ .vjs-play-control {
+ @include margin-left(0);
-.vjs-peertube-skin.vjs-has-captions .vjs-caption-toggle-control {
- display: block !important;
+ width: 30px;
+ }
+
+ &.vjs-live {
+ .vjs-current-time {
+ display: none !important;
+ }
+ }
}
diff --git a/client/src/sass/player/dock.scss b/client/src/sass/player/dock.scss
index 1dce24d30b..dc6e81285f 100644
--- a/client/src/sass/player/dock.scss
+++ b/client/src/sass/player/dock.scss
@@ -71,42 +71,43 @@
}
}
- @media screen and (max-width: $screen-width-750) {
- .peertube-dock-avatar {
- --avatarSize: 40px;
- }
+ &.vjs-playing.vjs-user-inactive .peertube-dock {
+ opacity: 0;
+ transition: opacity 1s;
+ }
+}
- .peertube-dock {
- font-size: 16px;
- }
+.video-js.vjs-peertube-skin.vjs-size-750 {
+ .peertube-dock-avatar {
+ --avatarSize: 40px;
+ }
- .peertube-dock-description {
- font-size: 9px;
- }
+ .peertube-dock {
+ font-size: 16px;
}
- @media screen and (max-width: $screen-width-570) {
- .peertube-dock-avatar {
- --avatarSize: 35px;
- }
+ .peertube-dock-description {
+ font-size: 9px;
+ }
+}
- .peertube-dock {
- font-size: 14px;
- }
+
+.video-js.vjs-peertube-skin.vjs-size-570 {
+ .peertube-dock-avatar {
+ --avatarSize: 35px;
}
- @media screen and (max-width: $screen-width-350) {
- .peertube-dock-avatar {
- --avatarSize: 30px;
- }
+ .peertube-dock {
+ font-size: 14px;
+ }
+}
- .peertube-dock {
- font-size: 13px;
- }
+.video-js.vjs-peertube-skin.vjs-size-350 {
+ .peertube-dock-avatar {
+ --avatarSize: 30px;
}
- &.vjs-playing.vjs-user-inactive .peertube-dock {
- opacity: 0;
- transition: opacity 1s;
+ .peertube-dock {
+ font-size: 13px;
}
}
diff --git a/client/src/sass/player/peertube-skin.scss b/client/src/sass/player/peertube-skin.scss
index ed3a6ac258..88b24d6435 100644
--- a/client/src/sass/player/peertube-skin.scss
+++ b/client/src/sass/player/peertube-skin.scss
@@ -114,39 +114,6 @@ body {
background-size: cover;
}
- @media screen and (max-width: $screen-width-750) {
- .vjs-big-play-button {
- font-size: 5em;
- border-width: 3px;
-
- .vjs-icon-placeholder::before {
- @include big-play-button-triangle-size(32px);
- }
- }
- }
-
- @media screen and (max-width: $screen-width-570) {
- .vjs-big-play-button {
- font-size: 4.5em;
- border-width: 2.5px;
-
- .vjs-icon-placeholder::before {
- @include big-play-button-triangle-size(27px);
- }
- }
- }
-
- @media screen and (max-width: $screen-width-350) {
- .vjs-big-play-button {
- font-size: 3em;
- border-width: 2px;
-
- .vjs-icon-placeholder::before {
- @include big-play-button-triangle-size(20px);
- }
- }
- }
-
// Theater mode is enabled
&.vjs-theater-enabled {
.vjs-theater-control {
@@ -229,3 +196,30 @@ body {
display: block;
}
}
+
+
+// ---------------------------------------------------------------------------
+// Custom media queries
+// ---------------------------------------------------------------------------
+
+.video-js.vjs-peertube-skin.vjs-size-570 {
+ .vjs-big-play-button {
+ font-size: 5em;
+ border-width: 3px;
+
+ .vjs-icon-placeholder::before {
+ @include big-play-button-triangle-size(32px);
+ }
+ }
+}
+
+.video-js.vjs-peertube-skin.vjs-size-350 {
+ .vjs-big-play-button {
+ font-size: 3em;
+ border-width: 2px;
+
+ .vjs-icon-placeholder::before {
+ @include big-play-button-triangle-size(20px);
+ }
+ }
+}