From 203d594f2d20c6a573e80f7044cce4bce5dd72a9 Mon Sep 17 00:00:00 2001 From: Aman Sharma Date: Mon, 10 Aug 2020 12:02:10 +0530 Subject: [PATCH] Resume video playback on close of support modal (#3052) * Resume video playback on close of support modal #2995 * Fix lint issues --- .../modal/video-support.component.ts | 4 +++- .../+video-watch/video-watch.component.ts | 23 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/client/src/app/+videos/+video-watch/modal/video-support.component.ts b/client/src/app/+videos/+video-watch/modal/video-support.component.ts index 48d5f2948..bd5290a72 100644 --- a/client/src/app/+videos/+video-watch/modal/video-support.component.ts +++ b/client/src/app/+videos/+video-watch/modal/video-support.component.ts @@ -21,9 +21,11 @@ export class VideoSupportComponent { ) { } show () { - this.modalService.open(this.modal, { centered: true }) + const modalRef = this.modalService.open(this.modal, { centered: true }) this.markdownService.enhancedMarkdownToHTML(this.video.support) .then(r => this.videoHTMLSupport = r) + + return modalRef } } diff --git a/client/src/app/+videos/+video-watch/video-watch.component.ts b/client/src/app/+videos/+video-watch/video-watch.component.ts index d8136ab4f..33f998282 100644 --- a/client/src/app/+videos/+video-watch/video-watch.component.ts +++ b/client/src/app/+videos/+video-watch/video-watch.component.ts @@ -236,9 +236,18 @@ export class VideoWatchComponent implements OnInit, OnDestroy { } showSupportModal () { + // Check video was playing before opening support modal + const isVideoPlaying = this.isPlaying() + this.pausePlayer() - this.videoSupportModal.show() + const modalRef = this.videoSupportModal.show() + + modalRef.result.then(() => { + if (isVideoPlaying) { + this.resumePlayer() + } + }) } showShareModal () { @@ -757,6 +766,18 @@ export class VideoWatchComponent implements OnInit, OnDestroy { this.player.pause() } + private resumePlayer () { + if (!this.player) return + + this.player.play() + } + + private isPlaying () { + if (!this.player) return + + return !this.player.paused() + } + private initHotkeys () { this.hotkeys = [ // These hotkeys are managed by the player