WebView - YouTube videos not playing

I have an activity that displays a webpage using a WebView. There is a link to a YouTube video on this page (so this is not a video that I can or need to embed).

The problem is that the video does not play - I see a preview image of the video using the click icon, but when I click on it there is no answer. Is there anything that can be done?

public class DisplayWebPage extends Activity
{   
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.display_web_page);

        Bundle extras = getIntent().getExtras();
        String url = extras.getString("url");
        WebView webview = (WebView)findViewById(R.id.WebView1);

        webview.setWebViewClient(new WebViewClient());
        webview.getSettings().setJavaScriptEnabled(true);
        webview.loadUrl(url);
    }
}
+1
source share
1 answer
public class MyPdfViewActivity extends Activity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    WebView mWebView=new WebView(MyPdfViewActivity.this);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setPluginsEnabled(true);
    mWebView.loadUrl(youtube_link);
    setContentView(mWebView);
  }
}

Update :: If the above postulate works, try using below:

public class main extends Activity {
    /** Called when the activity is first created. */
     @ Override


     public void onCreate (Bundle savedInstanceState) {
         super. onCreate (savedInstanceState);



         setContentView (R.layout.main);

         WebView web = (WebView) findViewById (R.id.webView);
         web. getSettings().setJavaScriptEnabled (true); 
         web. getSettings().setJavaScriptCanOpenWindowsAutomatically (false);
         web. getSettings().setPluginsEnabled (true);
         web. getSettings().setSupportMultipleWindows (false);
         web. getSettings().setSupportZoom (false);
         web. setVerticalScrollBarEnabled (false);
         web. setHorizontalScrollBarEnabled (false);


         web. loadUrl ("THE URL TO YOUR WEBVIEW SITE SHOULD GO HERE");

         web. setWebViewClient (new WebViewClient () {
             @ Override public boolean shouldOverrideUrlLoading(WebView view, String url) {
             if (url.startsWith("vnd.youtube")){

             startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));

             return true;
             }
             else
             {
             return false;
             }
             }
         });
     }

 } 
+5
source

All Articles