我的应用程序中有一个简单的WKWebView控制器,可加载本地HTML文件。 HTML文件,包括以下代码...
<audio autoplay="true" controls>
<source src="./audio/sound.mp3" type="audio/mpeg">
Your browser does not support the audio tag.
</audio>
一切正常,但是当用户滚动Web视图时,声音停止,滚动结束后,继续播放。
override func viewDidLoad() {
super.viewDidLoad()
let htmlPath = Bundle.main.path(forResource: "main", ofType: "htm", inDirectory: "level")
let url = URL(fileURLWithPath: htmlPath!)
let request = URLRequest(url: url)
webView.load(request)
}
尝试加载远程文件,但问题相同:
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "https://www.computerhope.com/jargon/h/html-audio-tag.htm")!
let request = URLRequest(url: url)
webView.load(request)
}
iOS版本:12.1
答案 0 :(得分:0)
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "https://www.computerhope.com/jargon/h/html-audio-tag.htm")!
myWebKit.load(URLRequest(url: url))
myWebKit.allowsBackForwardNavigationGestures = true
// Do any additional setup after loading the view.
}
我尝试了这段代码..它对我来说工作正常..滚动页面时音频仍在播放
myWebKit.allowsBackForwardNavigationGestures = true
尝试