Skip to content

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

Use server video ratio if available

Chocobozzzdfe98695d6de
diff --git a/client/src/app/+videos/+video-watch/video-watch.component.ts b/client/src/app/+videos/+video-watch/video-watch.component.ts
index 23c0fba5bc..b748551876 100644
--- a/client/src/app/+videos/+video-watch/video-watch.component.ts
+++ b/client/src/app/+videos/+video-watch/video-watch.component.ts
@@ -778,6 +778,8 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
videoShortUUID: video.shortUUID,
videoUUID: video.uuid,
+ videoRatio: video.aspectRatio,
+
previousVideo: {
enabled: this.playlist && this.videoWatchPlaylist.hasPreviousVideo(),
diff --git a/client/src/assets/player/peertube-player.ts b/client/src/assets/player/peertube-player.ts
index b6b6382fd5..df0cc15e74 100644
--- a/client/src/assets/player/peertube-player.ts
+++ b/client/src/assets/player/peertube-player.ts
@@ -375,6 +375,8 @@ export class PeerTubePlayer {
videoUUID: () => this.currentLoadOptions.videoUUID,
subtitle: () => this.currentLoadOptions.subtitle,
+ videoRatio: () => this.currentLoadOptions.videoRatio,
+
poster: () => this.currentLoadOptions.poster,
autoPlayerRatio: this.options.autoPlayerRatio
diff --git a/client/src/assets/player/shared/peertube/peertube-plugin.ts b/client/src/assets/player/shared/peertube/peertube-plugin.ts
index b8e918eac7..c7c36103a6 100644
--- a/client/src/assets/player/shared/peertube/peertube-plugin.ts
+++ b/client/src/assets/player/shared/peertube/peertube-plugin.ts
@@ -225,18 +225,31 @@ class PeerTubePlugin extends Plugin {
const defaultRatio = getComputedStyle(this.player.el()).getPropertyValue(this.options.autoPlayerRatio.cssRatioVariable)
+ if (this.options.videoRatio()) {
+ this.adaptPlayerFromRatio({ ratio: this.options.videoRatio(), defaultRatio })
+ }
+
this.player.on('video-ratio-changed', (_event, data: { ratio: number }) => {
- const el = this.player.el() as HTMLElement
+ this.adaptPlayerFromRatio({ ratio: data.ratio, defaultRatio })
+ })
+ }
- // In portrait screen mode, we allow player with bigger height size than width
- const portraitMode = getComputedStyle(el).getPropertyValue(this.options.autoPlayerRatio.cssPlayerPortraitModeVariable) === '1'
+ private adaptPlayerFromRatio (options: {
+ ratio: number
+ defaultRatio: string
+ }) {
+ const { ratio, defaultRatio } = options
- const currentRatio = isNaN(data.ratio) || (!portraitMode && data.ratio < 1)
- ? defaultRatio
- : data.ratio
+ const el = this.player.el() as HTMLElement
- el.style.setProperty('--player-ratio', currentRatio + '')
- })
+ // In portrait screen mode, we allow player with bigger height size than width
+ const portraitMode = getComputedStyle(el).getPropertyValue(this.options.autoPlayerRatio.cssPlayerPortraitModeVariable) === '1'
+
+ const currentRatio = isNaN(ratio) || (!portraitMode && ratio < 1)
+ ? defaultRatio
+ : ratio
+
+ el.style.setProperty('--player-ratio', currentRatio + '')
}
// ---------------------------------------------------------------------------
diff --git a/client/src/assets/player/types/peertube-player-options.ts b/client/src/assets/player/types/peertube-player-options.ts
index 4efabf6720..5ba73374d0 100644
--- a/client/src/assets/player/types/peertube-player-options.ts
+++ b/client/src/assets/player/types/peertube-player-options.ts
@@ -77,6 +77,7 @@ export type PeerTubePlayerLoadOptions = {
videoShortUUID: string
duration: number
+ videoRatio: number
requiresUserAuth: boolean
videoFileToken: () => string
diff --git a/client/src/assets/player/types/peertube-videojs-typings.ts b/client/src/assets/player/types/peertube-videojs-typings.ts
index 3aad7f4927..7aec818ad0 100644
--- a/client/src/assets/player/types/peertube-videojs-typings.ts
+++ b/client/src/assets/player/types/peertube-videojs-typings.ts
@@ -129,6 +129,8 @@ type PeerTubePluginOptions = {
videoUUID: () => string
subtitle: () => string
+ videoRatio: () => number
+
poster: () => string
}
diff --git a/client/src/standalone/videos/shared/player-options-builder.ts b/client/src/standalone/videos/shared/player-options-builder.ts
index 6294765018..6dd8520e36 100644
--- a/client/src/standalone/videos/shared/player-options-builder.ts
+++ b/client/src/standalone/videos/shared/player-options-builder.ts
@@ -290,6 +290,7 @@ export class PlayerOptionsBuilder {
videoUUID: video.uuid,
duration: video.duration,
+ videoRatio: video.aspectRatio,
poster: window.location.origin + video.previewPath,