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 --- client/src/standalone/videos/embed.ts | 45 ++++++++++++++++------ .../videos/shared/player-manager-options.ts | 4 ++ 2 files changed, 37 insertions(+), 12 deletions(-) (limited to 'client/src/standalone/videos') diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts index 2b826b9a2..5bb3b43c2 100644 --- a/client/src/standalone/videos/embed.ts +++ b/client/src/standalone/videos/embed.ts @@ -8,7 +8,16 @@ import { PeertubePlayerManager } from '../../assets/player' import { TranslationsManager } from '../../assets/player/translations-manager' import { getParamString, logger, videoRequiresAuth } from '../../root-helpers' import { PeerTubeEmbedApi } from './embed-api' -import { AuthHTTP, LiveManager, PeerTubePlugin, PlayerManagerOptions, PlaylistFetcher, PlaylistTracker, Translations, VideoFetcher } from './shared' +import { + AuthHTTP, + LiveManager, + PeerTubePlugin, + PlayerManagerOptions, + PlaylistFetcher, + PlaylistTracker, + Translations, + VideoFetcher +} from './shared' import { PlayerHTML } from './shared/player-html' export class PeerTubeEmbed { @@ -81,7 +90,7 @@ export class PeerTubeEmbed { if (!videoId) return - return this.loadVideoAndBuildPlayer(videoId) + return this.loadVideoAndBuildPlayer({ uuid: videoId, forceAutoplay: false }) } private async initPlaylist () { @@ -138,7 +147,7 @@ export class PeerTubeEmbed { this.playlistTracker.setCurrentElement(next) - return this.loadVideoAndBuildPlayer(next.video.uuid) + return this.loadVideoAndBuildPlayer({ uuid: next.video.uuid, forceAutoplay: false }) } async playPreviousPlaylistVideo () { @@ -150,7 +159,7 @@ export class PeerTubeEmbed { this.playlistTracker.setCurrentElement(previous) - await this.loadVideoAndBuildPlayer(previous.video.uuid) + await this.loadVideoAndBuildPlayer({ uuid: previous.video.uuid, forceAutoplay: false }) } getCurrentPlaylistPosition () { @@ -159,17 +168,28 @@ export class PeerTubeEmbed { // --------------------------------------------------------------------------- - private async loadVideoAndBuildPlayer (uuid: string) { + private async loadVideoAndBuildPlayer (options: { + uuid: string + forceAutoplay: boolean + }) { + const { uuid, forceAutoplay } = options + try { const { videoResponse, captionsPromise } = await this.videoFetcher.loadVideo(uuid) - return this.buildVideoPlayer(videoResponse, captionsPromise) + return this.buildVideoPlayer({ videoResponse, captionsPromise, forceAutoplay }) } catch (err) { this.playerHTML.displayError(err.message, await this.translationsPromise) } } - private async buildVideoPlayer (videoResponse: Response, captionsPromise: Promise) { + private async buildVideoPlayer (options: { + videoResponse: Response + captionsPromise: Promise + forceAutoplay: boolean + }) { + const { videoResponse, captionsPromise, forceAutoplay } = options + const alreadyHadPlayer = this.resetPlayerElement() const videoInfoPromise = videoResponse.json() @@ -201,7 +221,7 @@ export class PeerTubeEmbed { const PlayerManager: typeof PeertubePlayerManager = PeertubePlayerManagerModule.PeertubePlayerManager - const options = await this.playerManagerOptions.getPlayerOptions({ + const playerOptions = await this.playerManagerOptions.getPlayerOptions({ video, captionsResponse, alreadyHadPlayer, @@ -211,16 +231,17 @@ export class PeerTubeEmbed { authorizationHeader: () => this.http.getHeaderTokenValue(), videoFileToken: () => videoFileToken, - onVideoUpdate: (uuid: string) => this.loadVideoAndBuildPlayer(uuid), + onVideoUpdate: (uuid: string) => this.loadVideoAndBuildPlayer({ uuid, forceAutoplay: false }), playlistTracker: this.playlistTracker, playNextPlaylistVideo: () => this.playNextPlaylistVideo(), playPreviousPlaylistVideo: () => this.playPreviousPlaylistVideo(), - live + live, + forceAutoplay }) - this.player = await PlayerManager.initialize(this.playerManagerOptions.getMode(), options, (player: videojs.Player) => { + this.player = await PlayerManager.initialize(this.playerManagerOptions.getMode(), playerOptions, (player: videojs.Player) => { this.player = player }) @@ -256,7 +277,7 @@ export class PeerTubeEmbed { video, onPublishedVideo: () => { this.liveManager.stopListeningForChanges(video) - this.loadVideoAndBuildPlayer(video.uuid) + this.loadVideoAndBuildPlayer({ uuid: video.uuid, forceAutoplay: true }) } }) diff --git a/client/src/standalone/videos/shared/player-manager-options.ts b/client/src/standalone/videos/shared/player-manager-options.ts index 87a84975b..9ec012369 100644 --- a/client/src/standalone/videos/shared/player-manager-options.ts +++ b/client/src/standalone/videos/shared/player-manager-options.ts @@ -155,6 +155,8 @@ export class PlayerManagerOptions { captionsResponse: Response live?: LiveVideo + forceAutoplay: boolean + authorizationHeader: () => string videoFileToken: () => string @@ -175,6 +177,7 @@ export class PlayerManagerOptions { alreadyHadPlayer, videoFileToken, translations, + forceAutoplay, playlistTracker, live, authorizationHeader, @@ -187,6 +190,7 @@ export class PlayerManagerOptions { common: { // Autoplay in playlist mode autoplay: alreadyHadPlayer ? true : this.autoplay, + forceAutoplay, controls: this.controls, controlBar: this.controlBar, -- cgit v1.2.3