每当在其中打开此网页时,我都无法从 Android WebView 播放音频和视频。这两个链接都支持 HTML5。 WebView 无法正常播放音频和视频。
示例网页链接:
音频 - https://kulturpunkt.org/owner/49/group/175/record/3550
视频 - https://kulturpunkt.org/owner/49/group/175/record/3285
尝试过的解决方案:
1. Earlier, the Audio and Video links were not secure (https), we now changed it to secure link (https). This was done based on below errors
音频错误:Screenshot
I/chromium: [INFO:CONSOLE(13)] "Mixed Content: The page at 'https://kulturpunkt.org/owner/49/group/175/record/3550' was loaded over HTTPS, but requested an insecure video 'http://mm.dimu.org/multimedia/032wX1jg2tKY.mp3?mmid=032wX1jg2tKY&a=none'. This request has been blocked; the content must be served over HTTPS.", source: https://kulturpunkt.org/assets/kp.footer.2.0.19.js (13)
I/chromium: [INFO:CONSOLE(0)] "Uncaught (in promise) NotSupportedError: Failed to load because no supported source was found.", source: https://kulturpunkt.org/owner/49/group/175/record/3550 (0)
视频错误:Screenshot
I/chromium: [INFO:CONSOLE(13)] "Mixed Content: The page at 'https://kulturpunkt.org/owner/49/group/175/record/3285' was loaded over HTTPS, but requested an insecure video 'http://mm.dimu.org/multimedia/012wWXC2dbyh.mp4?mmid=012wWXC2dbyh&a=none'. This content should also be served over HTTPS.", source: https://kulturpunkt.org/assets/kp.footer.2.0.19.js
I/chromium: [INFO:CONSOLE(0)] "Uncaught (in promise) NotSupportedError: Failed to load because no supported source was found.", source: https://kulturpunkt.org/owner/49/group/175/record/3550 (0)
2. Second, I reduced the size of the Audio and Video to 7.33MB and 25.6MB as I thought Size might not be allowing the media to load properly and play in the WebView.
3. Finally, we tried to change the codecs of the Audio and Video to the supported formats by the Android WebView.
4. The Android System WebView app is also updated from Play Store in the device with OS Android 6.0 (M).
App Version - 55.0.2883.91 (09 Dec 2016)
我尝试在具有不同操作系统的所有不同设备上对其进行测试,但 Android WebView 行为保持不变。
我不明白这里到底是什么问题。我该如何解决这个问题?
I cannot use JavascriptInterface as explained in this answer, Even though, I have control over the server changes and the app changes. I want to implement it with default behavior of WebView.
下面是我的 WebView 的代码:
inAppWebView = (WebView)findViewById(R.id.in_app_web_view);
inAppWebView.setWebChromeClient(new MyWebChromeClient());
inAppWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
inAppWebView.loadUrl(webURL);
return true;
}
public void onLoadResource(WebView view, String url) {
dismissProgressDialog();
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
loadProgressDialog(InAppWebViewActivity.this);
super.onPageStarted(view, url, favicon);
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
dismissProgressDialog();
super.onReceivedError(view, request, error);
}
public void onPageFinished(WebView view, String url) {
dismissProgressDialog();
super.onPageFinished(view, url);
}
});
inAppWebView.getSettings().setDomStorageEnabled(true);
inAppWebView.getSettings().setJavaScriptEnabled(true);
inAppWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
inAppWebView.loadUrl(webURL);
任何建议或引用都会有所帮助。
最佳答案
将此添加到您的 list 文件中。
android:usesCleartextTraffic="true"
这是在创建您的 webview 之后if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
webView.getSettings().setMixedContentMode(
WebSettings.MIXED_CONTENT_ALWAYS_ALLOW );
}
关于android - 音频和视频未在 Android WebView HTML5 中播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41930024/