我的 Android 项目中的 Webview 有问题

问题描述 投票:0回答:1

webview 中的

 webView.settings.apply {
            javaScriptEnabled = true
            domStorageEnabled = true
            mediaPlaybackRequiresUserGesture = false
        }

 webView.webViewClient = object : WebViewClient() {
            override fun onPageFinished(view: WebView?, url: String?) {
                super.onPageFinished(view, url)

                val jsCode = """
                    function setPoster() {
                        console.log('Poster ayarlama başladı');
                        var videos = document.getElementsByTagName('video');
                        console.log('Video sayısı:', videos.length);
                        
                        for(var i = 0; i < videos.length; i++) {
                            var video = videos[i];
                            video.poster = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=';
                            console.log('Video ' + i + ' poster ayarlandı');
                        }
                    }
                    
                    setPoster();
                """
                view?.evaluateJavascript(jsCode, null)
            }
}
javascript java android kotlin webview
1个回答
0
投票

与 onPageFinished 相同,有一个名为 onPageStarted() 的方法,您可以使用它在加载之前显示您自己的自定义加载器

否则

domStorageEnabled = true; mediaPlaybackRequiresUserGesture = false;

用这两个删除并告诉我你是否得到它

© www.soinside.com 2019 - 2024. All rights reserved.