开发过程中有页面通过WKWebView加载的h5页面,h5页面带视频播放功能,想离开页面时,跟H5无交互的停止视频播放,方式如下:
public override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
if let webCell = self.webCell {
webCell.webV.evaluateJavaScript("var videos = document.getElementsByTagName('video');for (var i=0;i < videos.length;i++){videos[i].pause();}") { obj, error in
hvm_print("executeJsFunctionError -->\(error)", classObj: self, line: #line)
}
}
}