Merge pull request #1667 from hartlco/1647-video-keeps-playing-after-swiping-to-another-article

Stop media playback when article will disappear
This commit is contained in:
Maurice Parker
2020-01-20 10:56:14 -08:00
committed by GitHub
2 changed files with 21 additions and 0 deletions

View File

@@ -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()

View File

@@ -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();
});
}