2

I am using a WebView Class for playing the youtube video.

Code snippet:

public class WebViewPlayer extends Activity {

    private WebView engine;
    private String video_id = "bIPcobKMB94";
    // private String video_id ="Q-GLuydiMe4";  // **Not Playing**

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_web_view_player);

        engine = (WebView) findViewById(R.id.webview);

        engine.setWebViewClient(new WebViewClient());

        engine.getSettings().setAllowFileAccess(true); 
        engine.getSettings().setJavaScriptEnabled(true);

        engine.loadUrl("http://www.youtube.com/embed/"+video_id+"?autoplay=1");
    }
} 

In this code video_id which is commented, is not playing in the WebView. After the buffering a message is shown :

"This video contains content from VEVO. Is is restricted from playback on certain sites. Watech On Youtube"

Please have a look on this. And suggest me what should I do ?


EDIT 1:

engine = (WebView) findViewById(R.id.webview);  // Vevo restriction but Zooming Capability
        engine.setWebChromeClient(new WebChromeClient());
        engine.getSettings().setAllowFileAccess(true); 
        engine.getSettings().setJavaScriptEnabled(true);
        engine.getSettings().setPluginState(PluginState.ON);
        engine.setWebViewClient(new WebViewClient());
        engine.setBackgroundColor(0x00000000);
        engine.getSettings().setBuiltInZoomControls(true);
        String html = "<iframe width='420' height='345' src='http://www.youtube.com/embed/bIPcobKMB94' frameborder='0' allowfullscreen></iframe>";
        engine.loadDataWithBaseURL(null, html, "text/html", "UTF-8", null);

But when I pass the video_id = "Q-GLuydiMe4". VEVO restricted content will display on it.

Vevo id link this is not playing


EDit 2

I checked with all setting for webview

  • engine.getSettings().setJavaScriptEnabled(true);
  • engine.getSettings().setAppCacheEnabled(true);
  • engine.getSettings().setDomStorageEnabled(true);
  • engine.getSettings().setAllowContentAccess(true);
  • engine.getSettings().setAllowFileAccessFromFileURLs(true);
  • engine.getSettings().setAllowUniversalAccessFromFileURLs(true);
  • engine.getSettings().setBlockNetworkLoads(true);
  • engine.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
  • engine.getSettings().setPluginState(PluginState.ON);
  • engine.getSettings().setUseWideViewPort(true);

But still video is not run in the WebView

Please suggest me what should i Do ??? have anyone aware from this thing

Akarsh M
  • 1,629
  • 2
  • 24
  • 47
  • I met the same problem and answer it in another question, see http://stackoverflow.com/a/33252413/4662374 – Xu Bin Oct 21 '15 at 06:34

1 Answers1

1

Content owners can domain level white list or black list your source, which basically means you can't play them. Unfortunately I don't believe that there is any easy way to work around this.

timeshift117
  • 1,720
  • 2
  • 18
  • 21
  • 1
    But this is not happening in iOS. I played same Video_id in iOS webView class. It work fine in it. So What is reason in the Android. – Akarsh M Feb 15 '14 at 06:24
  • I can't say for sure but it is possible for Vevo to differentiate between iOS and Android, as to there reason for doing this, its not really possible to tell unless they've released a statement about it. – timeshift117 Feb 15 '14 at 06:26
  • I have implemented custom player (Using Video View ) , in this also I faced the same problem and iOS also have the same problem. But Some app are playing the same video in there webview and Video player. I dont know how ? BUT VEVO is running in other music App. – Akarsh M Feb 15 '14 at 07:00
  • Have you taken a look at the answer by Neji in this SO question, it seems like it may be helpful. http://stackoverflow.com/questions/14770333/video-not-playing-in-android-webview – timeshift117 Feb 15 '14 at 07:08
  • I'll check it out but main problem is restricted video. That is main issue right now BUT thanks for spending your precious time with my problem :) – Akarsh M Feb 15 '14 at 07:17
  • No problem, sorry I haven't been able to help much – timeshift117 Feb 15 '14 at 07:18