From ff338f7ddae858383cc1146b4a2462ebd4dc7d47 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 8 Dec 2023 09:58:42 +0100 Subject: [PATCH] Fix embed when waiting for a live --- .../web-video-options-builder.ts | 2 +- .../shared/web-video/web-video-plugin.ts | 22 ++++++++++--------- .../ffmpeg-transcoding-wrapper.ts | 4 +++- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/client/src/assets/player/shared/player-options-builder/web-video-options-builder.ts b/client/src/assets/player/shared/player-options-builder/web-video-options-builder.ts index 9cf74d8ed..b69ab1d34 100644 --- a/client/src/assets/player/shared/player-options-builder/web-video-options-builder.ts +++ b/client/src/assets/player/shared/player-options-builder/web-video-options-builder.ts @@ -14,7 +14,7 @@ export class WebVideoOptionsBuilder { videoFiles: this.options.webVideo.videoFiles.length !== 0 ? this.options.webVideo.videoFiles - : this.options?.hls.videoFiles || [] + : this.options.hls?.videoFiles || [] } } } diff --git a/client/src/assets/player/shared/web-video/web-video-plugin.ts b/client/src/assets/player/shared/web-video/web-video-plugin.ts index 8f4db0680..0f5015c9a 100644 --- a/client/src/assets/player/shared/web-video/web-video-plugin.ts +++ b/client/src/assets/player/shared/web-video/web-video-plugin.ts @@ -27,7 +27,8 @@ class WebVideoPlugin extends Plugin { this.videoFiles = options.videoFiles this.videoFileToken = options.videoFileToken - this.updateVideoFile({ videoFile: this.pickAverageVideoFile(), isUserResolutionChange: false }) + const videoFile = this.pickAverageVideoFile() + if (videoFile) this.updateVideoFile({ videoFile, isUserResolutionChange: false }) this.onLoadedMetadata = () => { player.trigger('video-ratio-changed', { ratio: this.player.videoWidth() / this.player.videoHeight() }) @@ -36,19 +37,19 @@ class WebVideoPlugin extends Plugin { player.on('loadedmetadata', this.onLoadedMetadata) player.ready(() => { - this.buildQualities() - - this.setupNetworkInfoInterval() - if (this.videoFiles.length === 0) { this.player.addClass('disabled') return } + + this.buildQualities() + + this.setupNetworkInfoInterval() }) } dispose () { - clearInterval(this.networkInfoInterval) + if (this.networkInfoInterval) clearInterval(this.networkInfoInterval) if (this.onLoadedMetadata) this.player.off('loadedmetadata', this.onLoadedMetadata) if (this.onErrorHandler) this.player.off('error', this.onErrorHandler) @@ -58,7 +59,7 @@ class WebVideoPlugin extends Plugin { } getCurrentResolutionId () { - return this.currentVideoFile.resolution.id + return this.currentVideoFile?.resolution.id } updateVideoFile (options: { @@ -123,7 +124,7 @@ class WebVideoPlugin extends Plugin { private adaptPosterForAudioOnly () { // Audio-only (resolutionId === 0) gets special treatment - if (this.currentVideoFile.resolution.id === 0) { + if (this.currentVideoFile?.resolution.id === 0) { this.player.audioPosterMode(true) } else { this.player.audioPosterMode(false) @@ -154,6 +155,7 @@ class WebVideoPlugin extends Plugin { } private pickAverageVideoFile () { + if (!this.videoFiles || this.videoFiles.length === 0) return undefined if (this.videoFiles.length === 1) return this.videoFiles[0] const files = this.videoFiles.filter(f => f.resolution.id !== 0) @@ -165,7 +167,7 @@ class WebVideoPlugin extends Plugin { id: videoFile.resolution.id, label: this.buildQualityLabel(videoFile), height: videoFile.resolution.id, - selected: videoFile.id === this.currentVideoFile.id, + selected: videoFile.id === this.currentVideoFile?.id, selectCallback: () => this.updateVideoFile({ videoFile, isUserResolutionChange: true }) })) @@ -187,7 +189,7 @@ class WebVideoPlugin extends Plugin { return this.player.trigger('network-info', { source: 'web-video', http: { - downloaded: this.player.bufferedPercent() * this.currentVideoFile.size + downloaded: this.player.bufferedPercent() * this.currentVideoFile?.size } } as PlayerNetworkInfo) }, 1000) diff --git a/server/core/lib/live/shared/transcoding-wrapper/ffmpeg-transcoding-wrapper.ts b/server/core/lib/live/shared/transcoding-wrapper/ffmpeg-transcoding-wrapper.ts index 464686470..e8fd192ff 100644 --- a/server/core/lib/live/shared/transcoding-wrapper/ffmpeg-transcoding-wrapper.ts +++ b/server/core/lib/live/shared/transcoding-wrapper/ffmpeg-transcoding-wrapper.ts @@ -68,7 +68,9 @@ export class FFmpegTranscodingWrapper extends AbstractTranscodingWrapper { logger.debug('Killing ffmpeg after live abort of ' + this.videoUUID, this.lTags()) - this.ffmpegCommand.kill('SIGINT') + if (this.ffmpegCommand) { + this.ffmpegCommand.kill('SIGINT') + } this.aborted = true this.emit('end')