如何禁用在 webview 中播放的視頻中的畫中畫?當您通過網路轉到視頻時,它會打開iOS中的特殊自動播放是否可以隱藏圖片中的按鈕圖片?
self.activityIndicator.stopAnimating()
self.activityIndicator.isHidden = true
guard let vid = videosID else {return}
let weburl = NSURL(string: "https://mosesplayer.azurewebsites.net/Electronplayer/Viewer?vid=\(vid)&source=Mobile")
let request = NSMutableURLRequest(url: weburl! as URL)
print(xapt)
request.setValue( xapt , forHTTPHeaderField:"x-apt")
webView.configuration.allowsPictureInPictureMediaPlayback = false
self.webView.load( request as URLRequest)

uj5u.com熱心網友回復:
我認為不可能從 WebView 本身洗掉按鈕。您寧可將該disablePictureInPicture屬性添加到 HTML 視頻標簽中。
<video controls disablePictureInPicture controlsList="nodownload">
<source src="https://www.w3schools.com/html/mov_bbb.ogg" type="video/mp4">
<source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/ogg">
</video>
您可以通過將 JavaScript注入 WebView來更改 HTML 。
class MainVC: UIViewController {
@IBOutlet weak var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
// 1
webView.load(URLRequest(url: URL(string: "URL")!))
injectToPage()
}
// 2
// MARK: - Reading contents of files
private func readFileBy(name: String, type: String) -> String {
guard let path = Bundle.main.path(forResource: name, ofType: type) else {
return "Failed to find path"
}
do {
return try String(contentsOfFile: path, encoding: .utf8)
} catch {
return "Unkown Error"
}
}
// 3
// MARK: - Inject to web page
func injectToPage() {
let jsFile = readFileBy(name: "script", type: "js")
let jsScript = WKUserScript(source: jsFile, injectionTime: .atDocumentEnd, forMainFrameOnly: false)
webView.configuration.userContentController.addUserScript(jsScript)
}
}
腳本.js
let videos = document.getElementsByTagName('video');
for(let video of videos) {
video.setAttribute('disablePictureInPicture', '');
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/401022.html
下一篇:XPath語法的官方規范在哪里?
