音频和视频无法在Android WebView HTML5中播放

时间:2017-01-30 06:21:34

标签: android html5 android-webview html5-video html5-audio

无论何时在其中打开此网页,我都无法播放Android WebView中的音频和视频。这两个链接都支持HTML5。 WebView无法正常播放音频和视频。

示例网页链接:

音频 - https://kulturpunkt.org/owner/49/group/175/record/3550

视频 - https://kulturpunkt.org/owner/49/group/175/record/3285

解决方案:

  

1。之前,音频和视频链接不安全(https),我们现在将其更改为安全链接(https)。这是基于以下错误

完成的

音频错误: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. 其次,我将音频和视频的大小缩小为 7.33MB 25.6MB ,因为我认为大小可能不是允许媒体正确加载并在WebView中播放。

     

3。最后,我们尝试通过Android WebView将音频和视频的编解码器更改为支持的格式

     

4. Android System WebView 应用也会在Play OS 6.0(M)设备的Play商店中更新。 App Version - 55.0.2883.91 (09 Dec 2016)

我尝试在具有不同操作系统的所有不同设备中测试它,但Android WebView行为保持不变。

我不明白这里究竟是什么问题。我该如何解决这个问题?

  

我无法使用JavascriptInterface中所述的 this answer ,即使我已控制服务器更改和应用更改。我想用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);

任何建议或参考都会有所帮助。

1 个答案:

答案 0 :(得分:0)

将此添加到清单文件中。

android:usesCleartextTraffic="true"

创建网页视图后

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    webView.getSettings().setMixedContentMode( 
        WebSettings.MIXED_CONTENT_ALWAYS_ALLOW );
}