Error while loading video in webview android studio. E/chromium: WebContentsDelegate::CheckMediaAccessPermission: Not supported

Viewed 655

I am trying to build a video call application using Peerjs. So the video call will be displayed on the web view using html and javascript in the assest folder. The peerjs code is deployed on heroku and is working perfectly on web browser.

I am getting this error while connecting to video. Basically the other persons video is not loading.

E/chromium: [ERROR:web_contents_delegate.cc(218)]WebContentsDelegate::CheckMediaAccessPermission: Not supported.

This is the code i am using for setting up the webview

        binding.webView.settings.mediaPlaybackRequiresUserGesture = false
        binding.webView.settings.safeBrowsingEnabled = true
        binding.webView.settings.allowFileAccess = true
        binding.webView.addJavascriptInterface(VideoInterface(this), "Android")

        val cookieManager: CookieManager = CookieManager.getInstance()
        cookieManager.setAcceptThirdPartyCookies(binding.webView, true)

        @TargetApi(Build.VERSION_CODES.LOLLIPOP)
        binding.webView.webChromeClient = object: WebChromeClient() {
            override fun onPermissionRequest(request: PermissionRequest?) {
                request?.grant(request.resources);
            }
        }
        safeBrowsingIsInitialized = false

        if (WebViewFeature.isFeatureSupported(WebViewFeature.START_SAFE_BROWSING)) {
            WebViewCompat.startSafeBrowsing(root.context, ValueCallback<Boolean> { success ->
                safeBrowsingIsInitialized = true
                if (!success) {
                    Log.e("MY_APP_TAG", "Unable to initialize Safe Browsing!")
                }
            })
        } 

This is my manifest

   <uses-permission android:name="android.permission.CAMERA" />
   <uses-permission android:name="android.permission.RECORD_AUDIO" />

   <uses-permission android:name="android.webkit.PermissionRequest" />
   <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> 

1 Answers

In manifest add android:usesCleartextTraffic="true"

override fun onPermissionRequest(request: PermissionRequest?) {
                runOnUiThread {
                    request?.grant(request.resources)
                }
            }
Related