How to play video URL inside android webview

后端 未结 10 1478
谎友^
谎友^ 2020-12-10 12:51

I want to play video url inside my application webview but when i am run the application it showing only white screen . i had read some post on this and i have used that cod

相关标签:
10条回答
  • 2020-12-10 13:01

    For me this was the solution

    settings.setDomStorageEnabled(true);
    
    0 讨论(0)
  • 2020-12-10 13:05
    WebView webview = (WebView) findViewById(R.id.webView1);
        webview.setWebViewClient(new WebViewClient());
        webview.getSettings().setJavaScriptEnabled(true);
        webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        webview.getSettings().setPluginState(WebSettings.PluginState.ON);
        webview.getSettings().setMediaPlaybackRequiresUserGesture(false);
        webview.setWebChromeClient(new WebChromeClient());
        webview.loadUrl("https://www.youtube.com");
    

    also set in manifist file

     <application
        android:allowBackup="true"
        android:hardwareAccelerated="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    
    0 讨论(0)
  • 2020-12-10 13:09

    Try this.

    {
        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setDomStorageEnabled(true);
        settings.setMinimumFontSize(10);
        settings.setLoadWithOverviewMode(true);
        settings.setUseWideViewPort(true);
        settings.setBuiltInZoomControls(true);
        settings.setDisplayZoomControls(false);
        webView.setVerticalScrollBarEnabled(false);         
        webView.loadDataWithBaseURL(null, vUrl, "text/html", "UTF-8", null);
    }
    
    0 讨论(0)
  • 2020-12-10 13:10

    No you can't play the video by link in this case. To do this you should create an RTSP connection then you can play the video through an RTSP url in Webview. You can retrieve an RTSP connection from a server like Youtube.

    0 讨论(0)
  • 2020-12-10 13:11

    This may be an old question but this works:

        //Here Im loading the html file from disk
        String html_file = LoadData(file.getAbsolutePath());
    
        WebView myWebView = (WebView) view.findViewById(R.id.webView);
        myWebView.reload();
        myWebView.getSettings().setJavaScriptEnabled(true);
        myWebView.loadData(html_file, "text/html; charset="utf-8", "UTF-8");
    

    Use base64 encoded video data as your video source:

    //html_file
    <video controls>
       <source type="video/mp4" src="data:video/webm;base64,MY_BASE64_ENCODED VIDEO_HERE">
    </video>
    
    0 讨论(0)
  • 2020-12-10 13:16

    You need to load an HTML document that embeds the video inside of it, instead of the video directly. To play inline video in WebView using the <video> tag you must also ensure the hardware acceleration is enabled in your application (see http://developer.android.com/guide/topics/graphics/hardware-accel.html).

    0 讨论(0)
提交回复
热议问题