gpt4 book ai didi

android - 如何在 Android Web View 中嵌入 iframe 视频?

转载 作者:行者123 更新时间:2023-12-03 08:52:51 25 4
gpt4 key购买 nike

我想将以下视频嵌入到 Android WebView 中: https://www.espn.com.ar/core/video/iframe?id=6034792&endcard=false&omniReportSuite=wdgespg

我尝试了不同的 WebView 方法,但没有任何结果。没有错误,我只能查看播放器,但无法播放。

enter image description here

// list :

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

<application
...
android:hardwareAccelerated="true">

//代码:

String html = String.format("<iframe src=\"%s\" width=\"340\" height=\"313\" style=\"border:none;overflow:hidden\" scrolling=\"no\" frameborder=\"0\" allowTransparency=\"true\"></iframe>", url.getSrc());
wview.loadDataWithBaseURL("https://www.espn.com.ar", html, "text/html", "UTF-8", null);

//OR

wview.loadUrl(url.getSrc());

//MY WEBVIEW:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:wheel="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true">

<WebView
android:id="@+id/wview"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

</RelativeLayout>

最佳答案

请检查下面的代码,它对我来说工作正常,在 list 添加上 android:hardwareAccelerated="true"

WebView webview = findViewById(R.id.myweb);
webview.setWebChromeClient(new WebChromeClient());
webview.getSettings().setLoadsImagesAutomatically(true);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setAllowFileAccess(true);
webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webview.getSettings().setPluginState(WebSettings.PluginState.ON);
webview.getSettings().setMediaPlaybackRequiresUserGesture(false);
webview.getSettings().setDomStorageEnabled(true);
webview.getSettings().setAppCacheMaxSize(1024 * 8);
webview.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webview.requestFocus(View.FOCUS_DOWN);
webview.getSettings().setAppCacheEnabled(true);

webview.loadUrl("https://www.espn.com.ar");

关于android - 如何在 Android Web View 中嵌入 iframe 视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57858546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com