首页 > 解决方案 > 如何解决问题 webview 播放音频

问题描述

我使用我的网站WebView来创建我的网站的应用程序。我的网站有一个部分可以播放来自其他网站的声音。我的网站是https,其他网站是http。当想播放这首歌时,从 android studio 得到这个错误

    E/EGL_emulation: eglQueryContext 32c0  EGL_BAD_ATTRIBUTE
E/EGL_emulation: tid 3170: eglQueryContext(1456): error 0x3004 (EGL_BAD_ATTRIBUTE)
I/chromium: [INFO:CONSOLE(0)] "Mixed Content: The page at 'https://mysiteurl' was loaded over HTTPS, but requested an insecure video 'http://othersiteurl'. This request has been blocked; the content must be served over HTTPS.", source: https://mysiteurl (0)
I/chromium: [INFO:CONSOLE(0)] "Uncaught (in promise) NotSupportedError: Failed to load because no supported source was found.", source: undefined (0)

我该如何解决这个问题

标签: androidwebview

解决方案


你必须添加

android:usesCleartextTraffic="true"

到 AndroidManifest.xml 中的应用程序标签并添加

if (Build.VERSION.SDK_INT >= 21) {
        mWebView.getSettings().setMixedContentMode( WebSettings.MIXED_CONTENT_ALWAYS_ALLOW );
}

进入 OnCreate 你的活动


推荐阅读