WKWebView无法播放本地音频 [英] WKWebView fails to play local audio
问题描述
由于iOS9我们可以渲染一个 WKWebView
使用 loadFileURL本地HTML:allowingReadAccessToURL:
Since iOS9 we can render local HTML with a WKWebView
using loadFileURL:allowingReadAccessToURL:
这看起来不错,到目前为止,但我们有问题从HTML中扮演一个当地的mp3。
有一个<音频方式>
与MP3文件的相对路径src属性标记
This looks good so far, but we are having Problems playing a local mp3 from within the HTML.
There is an <audio>
tag with a src attribute with a relative path to the mp3 file.
该iOS9模拟器正确发挥我们的mp3,但设备不。醒目的JavaScript错误显示 networkState NETWORK_NO_SOURCE
,这没有任何意义对我们...
使用HTTP URL作为源文件和流的MP3从网络正常工作。
The iOS9-Simulator plays our mp3 correctly, but the Devices don't. Catching the Error with JavaScript shows a networkState NETWORK_NO_SOURCE
, which does not make sense to us...
Using an http URL as src and streaming the mp3 from the web works fine.
有没有人管理,以播放本地的音频文件与 WKWebView
?
Has anybody managed to play local audio files with a WKWebView
?
推荐答案
我也遇到了在iOS 9.2这个问题。与本地URL的视频将在模拟器上,但不是在设备上播放的罚款。使用Safari调试工具显示了视频错误的一样没有源错误。我们提出了雷达是: http://www.openradar.me/24281444
这里是疯狂的一部分 - 工作(无需运行本地Web主机)是,我们发现,如果你在一个UIWebView首先播放视频那么wkwebview视频将工作1缺憾的解决方法。我们采取了这样的一步,使用的是隐藏发挥半秒视频没有声音了曾在标签自动播放属性,Web视图一个UIWebView有 uiWebView.mediaPlaybackRequiresUserAction = FALSE
虽然因为什么,我已经看到它会导致WKWebview来,然后播放视频罚款哈克。因此多了一个解决方案,直到他们解决问题。
I also encountered this issue on iOS 9.2. A video with a local URL would play fine on the simulator but not on device. Debugging using Safari tools showed the video error to the the same No source error. We filed a radar for it: http://www.openradar.me/24281444
Here is the crazy part - one kludgy workaround that worked (without having to run a local web host) was that we found if you played a video first in a UIWebView then the wkwebview videos would work. We took this a step further and used a UIWebview that was hidden to play a half second video with no sound that had an autoplay attribute in the tag and the web view had
uiWebView.mediaPlaybackRequiresUserAction = false
While hacky as anything I have seen it causes the WKWebview to then play videos fine. So one more solution until they fix the issue.
这篇关于WKWebView无法播放本地音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!