Stop media playback when article will disappear

This commit is contained in:
Martin Hartl 2020-01-20 19:46:23 +01:00
parent bca3c4216c
commit 3370b834b0
2 changed files with 21 additions and 0 deletions

View File

@ -124,6 +124,12 @@ class WebViewController: UIViewController {
} }
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
stopMediaPlayback()
}
// MARK: Notifications // MARK: Notifications
@objc func webFeedIconDidBecomeAvailable(_ note: Notification) { @objc func webFeedIconDidBecomeAvailable(_ note: Notification) {
@ -527,6 +533,10 @@ private extension WebViewController {
} }
} }
func stopMediaPlayback() {
webView?.evaluateJavaScript("stopMediaPlayback();")
}
func configureTopShowBarsView() { func configureTopShowBarsView() {
topShowBarsView = UIView() topShowBarsView = UIView()
topShowBarsView.backgroundColor = .clear topShowBarsView.backgroundColor = .clear

View File

@ -145,3 +145,14 @@ function postRenderProcessing() {
ImageViewer.init(); ImageViewer.init();
inlineVideos(); inlineVideos();
} }
function stopMediaPlayback() {
document.querySelectorAll("iframe").forEach(element => {
var iframeSrc = element.src;
element.src = iframeSrc;
});
document.querySelectorAll("video, audio").forEach(element => {
element.pause();
});
}