0

I am playing YouTube videos in webview Android. First I am calling the JavaScript functions for getting the status of the YouTube video. When I get the status one at the only I am visible the webview until that webview is visible gone and loading the webview background.

It works fine, but after getting the YouTube video status I am visible the webview it is visible with black screen and spinner is rotating on that screen. Below is my screen:

My screen

Below is my simple code:

final MyJavaScriptInterface myJavaScriptInterface
        = new MyJavaScriptInterface(this);
    myBrowser.addJavascriptInterface(myJavaScriptInterface, "AndroidFunction");
    myBrowser.setWebViewClient(new WebViewClient());
    myBrowser.getSettings().setJavaScriptEnabled(true);
    myBrowser.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    myBrowser.getSettings().setPluginState(WebSettings.PluginState.ON);
    myBrowser.setWebChromeClient(new WebChromeClient());
    myBrowser.getSettings().setAppCacheEnabled(true);
    myBrowser.getSettings().setSaveFormData(true);
    myBrowser.setWebChromeClient(new WebChromeClient() {
    });
myBrowser.loadUrl("http://Xxxxxxxxxxx/player_android/youtube?videoid=txqiwrbYGrs&st=10&en=20&height=250&width=500&auto=1&ctrl=0&p2p=1");

At that time I click on the webview, the video is played successfully. Without touching the webview, the video is not shown on the screen. How to play the YouTube video in webview?

honk
  • 9,137
  • 11
  • 75
  • 83
Rajesh
  • 521
  • 5
  • 19

2 Answers2

0

Here you can play the video in WebView.

private String url = "http://"; // your video url here

     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.setWebChromeClient(new WebChromeClient());
     webview.loadUrl(url);
    }
}

How to play a video in a webview with android?

Community
  • 1
  • 1
Chaudhary Amar
  • 836
  • 8
  • 20
0
wv.setWebChromeClient(new WebChromeClient() {
});
Raidri
  • 17,258
  • 9
  • 62
  • 65
Ayush
  • 173
  • 1
  • 1
  • 12
  • Thanks for reply,as per my knowleadge without using the webchrome client javascript functions are not called.so already i am using the above code. – Rajesh Dec 23 '15 at 10:47