0

I am new in android and I am displaying a news link in a webview. News link is displaying properly but video in news link is not playing.

Link is :

http://aajtak.intoday.in/livetv.html

My code is:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    web = (WebView) findViewById(R.id.webview01);
    web.setWebViewClient(new myWebClient());
    web.getSettings().setJavaScriptEnabled(true);
    web.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    web.getSettings().setPluginState(PluginState.ON);        
    web.loadUrl("http://aajtak.intoday.in/karyakram/video/so-sorry-episode-of-10th-august-2016-on-delhi-aam-admi-party-mla-and-rajnath-singh-najeeb-jung-1-882177.html");
}

public class myWebClient extends WebViewClient
{
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        // TODO Auto-generated method stub
        super.onPageStarted(view, url, favicon);
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        // TODO Auto-generated method stub

      view.loadUrl(url);
      return true;
    }
}
Kurt Van den Branden
  • 11,995
  • 10
  • 76
  • 85
Nikita Gupta
  • 93
  • 1
  • 1
  • 5

2 Answers2

0

Try adding this code :

webView.setWebChromeClient(new WebChromeClient());
Parth Anjaria
  • 3,961
  • 3
  • 30
  • 62
  • I tried by turned on hardware acceleration and add your line also. Its working but the another problem is that after opening a link i have to click on video then video is playing. Is there any method to play video automatically ? – Nikita Gupta Aug 16 '16 at 04:37
0

To support video in webview, you need to have hardware acceleration turned on, and set a WebChromeClient. For full screen support, implementations of onShowCustomView(View, WebChromeClient.CustomViewCallback) and onHideCustomView() are required.

Used this, but now a days onShowCustomView() is deprecated.

from YouTube Video not playing in WebView - Android

Community
  • 1
  • 1
Nikhil Borad
  • 2,065
  • 16
  • 20
  • I tried by turned on hardware acceleration and add your line also. Its working but the another problem is that after opening a link i have to click on video then video is playing. Is there any method to play video automatically ? – Nikita Gupta Sep 16 '16 at 07:55
  • if you work with specific service like YouTube. then u can achieve it with trigger click with jquery on play button as soon as page finished with loading. n Ya Upvote :D – Nikhil Borad Sep 16 '16 at 09:07