0
votes

I have a simple WKWebView controller in my application that loads a local HTML file. HTML file including following code...

<audio autoplay="true" controls>
    <source src="./audio/sound.mp3" type="audio/mpeg">
    Your browser does not support the audio tag.
</audio>

Everything works fine, but when the user scrolls the webview, the sound stops, when the scrolling ends, the playback continues.

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)
}

Trying load remote file, but problem is same:

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 version: 12.1

1
may b playing audio in another thread can fix the issue..hmali
@hmali How i can playing audio in another thread? Audio coming with HTML fileuser3544668
I tried it .. its working fine audio is still running while scrolling the pagehmali

1 Answers

0
votes
 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.
}

I tried this code.. its working fine for me.. audio is still playing while scrolling the page

myWebKit.allowsBackForwardNavigationGestures = true

try this