【问题标题】:How to Embed a iframe video in Web View Android?如何在 Web View Android 中嵌入 iframe 视频?
【发布时间】:2020-01-11 11:43:12
【问题描述】:

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

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

//清单:

<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>

【问题讨论】:

标签: android video webview android-webview embed


【解决方案1】:

您是否添加了互联网权限

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

【讨论】:

    【解决方案2】:

    请检查下面的代码,它对我来说工作正常,在清单上添加 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");
    

    【讨论】:

    • 太棒了!!那行得通!我浪费了太多时间来寻找这个问题的解决方案。非常感谢:)
    猜你喜欢
    • 2016-07-25
    • 1970-01-01
    • 2012-05-29
    • 2017-05-11
    • 1970-01-01
    • 2016-10-09
    • 2012-10-22
    • 1970-01-01
    • 2022-01-10
    相关资源
    最近更新 更多