From 59a643aa5cf6775d27dfcc147b19c4537292d53c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 15 Nov 2022 11:57:49 +0100 Subject: Force autoplay when live starts Using the mute --- .../player/shared/manager-options/manager-options-builder.ts | 8 ++++++-- client/src/assets/player/shared/peertube/peertube-plugin.ts | 2 +- client/src/assets/player/shared/webtorrent/webtorrent-plugin.ts | 4 ++-- client/src/assets/player/types/manager-options.ts | 2 ++ client/src/assets/player/types/peertube-videojs-typings.ts | 4 ++-- 5 files changed, 13 insertions(+), 7 deletions(-) (limited to 'client/src/assets') diff --git a/client/src/assets/player/shared/manager-options/manager-options-builder.ts b/client/src/assets/player/shared/manager-options/manager-options-builder.ts index 2d96c9410..4d227eb2a 100644 --- a/client/src/assets/player/shared/manager-options/manager-options-builder.ts +++ b/client/src/assets/player/shared/manager-options/manager-options-builder.ts @@ -105,10 +105,12 @@ export class ManagerOptionsBuilder { Object.assign(videojsOptions, { language: commonOptions.language }) } + console.log(videojsOptions) + return videojsOptions } - private getAutoPlayValue (autoplay: any, alreadyPlayed: boolean) { + private getAutoPlayValue (autoplay: videojs.Autoplay, alreadyPlayed: boolean) { if (autoplay !== true) return autoplay // On first play, disable autoplay to avoid issues @@ -117,7 +119,9 @@ export class ManagerOptionsBuilder { return alreadyPlayed ? 'play' : false } - return 'play' + return this.options.common.forceAutoplay + ? 'any' + : 'play' } getContextMenuOptions (player: videojs.Player, commonOptions: CommonOptions) { diff --git a/client/src/assets/player/shared/peertube/peertube-plugin.ts b/client/src/assets/player/shared/peertube/peertube-plugin.ts index 56de66998..ec8fbb320 100644 --- a/client/src/assets/player/shared/peertube/peertube-plugin.ts +++ b/client/src/assets/player/shared/peertube/peertube-plugin.ts @@ -52,7 +52,7 @@ class PeerTubePlugin extends Plugin { this.videoCaptions = options.videoCaptions this.initialInactivityTimeout = this.player.options_.inactivityTimeout - if (options.autoplay) this.player.addClass('vjs-has-autoplay') + if (options.autoplay !== false) this.player.addClass('vjs-has-autoplay') this.player.on('autoplay-failure', () => { this.player.removeClass('vjs-has-autoplay') diff --git a/client/src/assets/player/shared/webtorrent/webtorrent-plugin.ts b/client/src/assets/player/shared/webtorrent/webtorrent-plugin.ts index 658b7c867..46d009410 100644 --- a/client/src/assets/player/shared/webtorrent/webtorrent-plugin.ts +++ b/client/src/assets/player/shared/webtorrent/webtorrent-plugin.ts @@ -25,7 +25,7 @@ class WebTorrentPlugin extends Plugin { private readonly playerElement: HTMLVideoElement - private readonly autoplay: boolean = false + private readonly autoplay: boolean | string = false private readonly startTime: number = 0 private readonly savePlayerSrcFunction: videojs.Player['src'] private readonly videoDuration: number @@ -449,7 +449,7 @@ class WebTorrentPlugin extends Plugin { return } - if (this.autoplay) { + if (this.autoplay !== false) { this.player.posterImage.hide() return this.updateVideoFile(undefined, { forcePlay: true, seek: this.startTime }) diff --git a/client/src/assets/player/types/manager-options.ts b/client/src/assets/player/types/manager-options.ts index 9da8fedf8..3057a5adb 100644 --- a/client/src/assets/player/types/manager-options.ts +++ b/client/src/assets/player/types/manager-options.ts @@ -36,6 +36,8 @@ export interface CommonOptions extends CustomizationOptions { onPlayerElementChange: (element: HTMLVideoElement) => void autoplay: boolean + forceAutoplay: boolean + p2pEnabled: boolean nextVideo?: () => void diff --git a/client/src/assets/player/types/peertube-videojs-typings.ts b/client/src/assets/player/types/peertube-videojs-typings.ts index f02673a66..3d9d5270e 100644 --- a/client/src/assets/player/types/peertube-videojs-typings.ts +++ b/client/src/assets/player/types/peertube-videojs-typings.ts @@ -91,7 +91,7 @@ type VideoJSCaption = { type PeerTubePluginOptions = { mode: PlayerMode - autoplay: boolean + autoplay: videojs.Autoplay videoDuration: number videoViewUrl: string @@ -143,7 +143,7 @@ type PeerTubeP2PInfoButtonOptions = { type WebtorrentPluginOptions = { playerElement: HTMLVideoElement - autoplay: boolean + autoplay: videojs.Autoplay videoDuration: number videoFiles: VideoFile[] -- cgit v1.2.3