mirror of https://github.com/Chocobozzz/PeerTube
Use server video ratio if available
parent
9953825499
commit
dfe98695d6
|
@ -778,6 +778,8 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
|
||||||
videoShortUUID: video.shortUUID,
|
videoShortUUID: video.shortUUID,
|
||||||
videoUUID: video.uuid,
|
videoUUID: video.uuid,
|
||||||
|
|
||||||
|
videoRatio: video.aspectRatio,
|
||||||
|
|
||||||
previousVideo: {
|
previousVideo: {
|
||||||
enabled: this.playlist && this.videoWatchPlaylist.hasPreviousVideo(),
|
enabled: this.playlist && this.videoWatchPlaylist.hasPreviousVideo(),
|
||||||
|
|
||||||
|
|
|
@ -375,6 +375,8 @@ export class PeerTubePlayer {
|
||||||
videoUUID: () => this.currentLoadOptions.videoUUID,
|
videoUUID: () => this.currentLoadOptions.videoUUID,
|
||||||
subtitle: () => this.currentLoadOptions.subtitle,
|
subtitle: () => this.currentLoadOptions.subtitle,
|
||||||
|
|
||||||
|
videoRatio: () => this.currentLoadOptions.videoRatio,
|
||||||
|
|
||||||
poster: () => this.currentLoadOptions.poster,
|
poster: () => this.currentLoadOptions.poster,
|
||||||
|
|
||||||
autoPlayerRatio: this.options.autoPlayerRatio
|
autoPlayerRatio: this.options.autoPlayerRatio
|
||||||
|
|
|
@ -225,18 +225,31 @@ class PeerTubePlugin extends Plugin {
|
||||||
|
|
||||||
const defaultRatio = getComputedStyle(this.player.el()).getPropertyValue(this.options.autoPlayerRatio.cssRatioVariable)
|
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 }) => {
|
this.player.on('video-ratio-changed', (_event, data: { ratio: number }) => {
|
||||||
|
this.adaptPlayerFromRatio({ ratio: data.ratio, defaultRatio })
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private adaptPlayerFromRatio (options: {
|
||||||
|
ratio: number
|
||||||
|
defaultRatio: string
|
||||||
|
}) {
|
||||||
|
const { ratio, defaultRatio } = options
|
||||||
|
|
||||||
const el = this.player.el() as HTMLElement
|
const el = this.player.el() as HTMLElement
|
||||||
|
|
||||||
// In portrait screen mode, we allow player with bigger height size than width
|
// In portrait screen mode, we allow player with bigger height size than width
|
||||||
const portraitMode = getComputedStyle(el).getPropertyValue(this.options.autoPlayerRatio.cssPlayerPortraitModeVariable) === '1'
|
const portraitMode = getComputedStyle(el).getPropertyValue(this.options.autoPlayerRatio.cssPlayerPortraitModeVariable) === '1'
|
||||||
|
|
||||||
const currentRatio = isNaN(data.ratio) || (!portraitMode && data.ratio < 1)
|
const currentRatio = isNaN(ratio) || (!portraitMode && ratio < 1)
|
||||||
? defaultRatio
|
? defaultRatio
|
||||||
: data.ratio
|
: ratio
|
||||||
|
|
||||||
el.style.setProperty('--player-ratio', currentRatio + '')
|
el.style.setProperty('--player-ratio', currentRatio + '')
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
|
@ -77,6 +77,7 @@ export type PeerTubePlayerLoadOptions = {
|
||||||
videoShortUUID: string
|
videoShortUUID: string
|
||||||
|
|
||||||
duration: number
|
duration: number
|
||||||
|
videoRatio: number
|
||||||
|
|
||||||
requiresUserAuth: boolean
|
requiresUserAuth: boolean
|
||||||
videoFileToken: () => string
|
videoFileToken: () => string
|
||||||
|
|
|
@ -129,6 +129,8 @@ type PeerTubePluginOptions = {
|
||||||
videoUUID: () => string
|
videoUUID: () => string
|
||||||
subtitle: () => string
|
subtitle: () => string
|
||||||
|
|
||||||
|
videoRatio: () => number
|
||||||
|
|
||||||
poster: () => string
|
poster: () => string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -290,6 +290,7 @@ export class PlayerOptionsBuilder {
|
||||||
videoUUID: video.uuid,
|
videoUUID: video.uuid,
|
||||||
|
|
||||||
duration: video.duration,
|
duration: video.duration,
|
||||||
|
videoRatio: video.aspectRatio,
|
||||||
|
|
||||||
poster: window.location.origin + video.previewPath,
|
poster: window.location.origin + video.previewPath,
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue