Skip to content

Commit

Permalink
Use server video ratio if available
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocobozzz committed Feb 27, 2024
1 parent 9953825 commit dfe9869
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 8 deletions.
2 changes: 2 additions & 0 deletions client/src/app/+videos/+video-watch/video-watch.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),

Expand Down
2 changes: 2 additions & 0 deletions client/src/assets/player/peertube-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 21 additions & 8 deletions client/src/assets/player/shared/peertube/peertube-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '')
}

// ---------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions client/src/assets/player/types/peertube-player-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export type PeerTubePlayerLoadOptions = {
videoShortUUID: string

duration: number
videoRatio: number

requiresUserAuth: boolean
videoFileToken: () => string
Expand Down
2 changes: 2 additions & 0 deletions client/src/assets/player/types/peertube-videojs-typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ type PeerTubePluginOptions = {
videoUUID: () => string
subtitle: () => string

videoRatio: () => number

poster: () => string
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ export class PlayerOptionsBuilder {
videoUUID: video.uuid,

duration: video.duration,
videoRatio: video.aspectRatio,

poster: window.location.origin + video.previewPath,

Expand Down

0 comments on commit dfe9869

Please sign in to comment.