Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play video URL inside android webview

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 code but video is not playing in webview it launch device player but my requirement not this .

please help me if some one already done this . my code is here :-

    WebView webView = (WebView) findViewById(R.id.myweb);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setPluginState(PluginState.ON);
    webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    webView.getSettings().setSupportMultipleWindows(true);
    webView.getSettings().setSupportZoom(true);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setAllowFileAccess(true);
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageFinished(WebView view, String url) {
            setProgressBarIndeterminateVisibility(false);
            super.onPageFinished(view, url);
        }
    });
    webView.loadUrl("http://download.wavetlan.com/SVV/Media/HTTP/H264/Talkinghead_Media/H264_test1_Talkinghead_mp4_480x360.mp4");
    webView.setVisibility(View.VISIBLE);

Testing URL is working in browser .

like image 835
Alok Tiwari Avatar asked Dec 02 '13 06:12

Alok Tiwari


People also ask

Can we play video in WebView Android?

For showing the video in our android application we will use the VideoView widget. The VideoView widget is capable of playing media files, and the formats supported by the VideoView are 3gp and MP4.

How can I make WebView keep a video or audio playing in the background?

After searching a lot, I found this thread. I did something similar: Just extend WebView and override onWindowVisibilityChanged . This way, the audio continues to play if the screen is locked or another app is opened.

How do I display HTML content in WebView?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code, we have taken web view to show html content.


1 Answers

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>
like image 59
wadali Avatar answered Sep 18 '22 13:09

wadali