From 3370b834b08d7a032682219daf73f2e290f17a6b Mon Sep 17 00:00:00 2001 From: Martin Hartl Date: Mon, 20 Jan 2020 19:46:23 +0100 Subject: [PATCH] Stop media playback when article will disappear --- iOS/Article/WebViewController.swift | 10 ++++++++++ iOS/Resources/main_ios.js | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/iOS/Article/WebViewController.swift b/iOS/Article/WebViewController.swift index fe26ed60c..b3fee9095 100644 --- a/iOS/Article/WebViewController.swift +++ b/iOS/Article/WebViewController.swift @@ -123,6 +123,12 @@ class WebViewController: UIViewController { } } + + override func viewWillDisappear(_ animated: Bool) { + super.viewWillDisappear(animated) + + stopMediaPlayback() + } // MARK: Notifications @@ -526,6 +532,10 @@ private extension WebViewController { coordinator.showFullScreenImage(image: image, imageTitle: clickMessage.imageTitle, transitioningDelegate: self) } } + + func stopMediaPlayback() { + webView?.evaluateJavaScript("stopMediaPlayback();") + } func configureTopShowBarsView() { topShowBarsView = UIView() diff --git a/iOS/Resources/main_ios.js b/iOS/Resources/main_ios.js index 0589f1cf2..646b53d50 100644 --- a/iOS/Resources/main_ios.js +++ b/iOS/Resources/main_ios.js @@ -145,3 +145,14 @@ function postRenderProcessing() { ImageViewer.init(); inlineVideos(); } + +function stopMediaPlayback() { + document.querySelectorAll("iframe").forEach(element => { + var iframeSrc = element.src; + element.src = iframeSrc; + }); + + document.querySelectorAll("video, audio").forEach(element => { + element.pause(); + }); +}