0

I am trying to load a video stream using android webview but the video fails to play returns error unsupported type. My code is as below

    starTvStream = ((MainActivity)mActivity).SESSION_STARTV_OTHER;
    mWebView  = (WebView) fragView.findViewById(R.id.streamWebView);
    WebSettings webSettings = mWebView.getSettings();
    mWebView.setWebViewClient(new WebViewClient());
    mWebView.setWebChromeClient(new WebChromeClient());
    mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
    mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    mWebView.loadUrl(starTvStream);

What could i b missing in my code. In the manifest i have enabled android:hardwareAccelerated="true" and permissions

android:name="android.permission.INTERNET" 
android:name="android.permission.WAKE_LOCK"
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
jmsiox
  • 123
  • 10
  • `webview.getSettings().setPluginsEnabled(true);` – AskNilesh Dec 11 '17 at 08:24
  • @Nilu does the method setPluginsEnabled exist or is it setPluginState – jmsiox Dec 11 '17 at 08:36
  • check this https://stackoverflow.com/questions/5383364/flash-video-not-displaying-in-webview-for-android-3-0-1 and this https://stackoverflow.com/questions/20802288/flash-is-not-loading-in-web-view-in-android – AskNilesh Dec 11 '17 at 08:38
  • https://stackoverflow.com/questions/18807352/enable-flash-into-a-webview-android-app – AskNilesh Dec 11 '17 at 08:38

1 Answers1

0

You have to override shouldOverrideUrlLoading() if you detect a URL with a supported video mimetype return true and then launch the default activity with the URL. Here is a sample.

mWebView.setWebViewClient(new WebViewClient(){

public boolean shouldOverrideUrlLoading(Webview view, String url){
     if(url.endsWith(".mp4") || url.endsWith("some other supported type")){
          Intent i = new Intent(Intent.ACTION_VIEW);
          i.setData(Uri.parse(url));
          startActivity(i); 
          //warning no error handling will cause force close if no media player on phone.
          return true;
     }
     else return false; 
}});

hope this helps.

Nawrez
  • 3,314
  • 8
  • 28
  • 42
  • This will however not enable playing that uunsupported type. I thought there was a way to add plugins for types not supported e.g swf type.. – jmsiox Dec 11 '17 at 08:35
  • You can check like : if (Build.VERSION.SDK_INT < 8) { webview.getSettings().setPluginsEnabled(true); } else { webview.getSettings().setPluginState(PluginState.ON); } – Nawrez Dec 11 '17 at 08:39