1

I have an activity which is displaying a web page using a WebView. Within that page, there is a link to a YouTube video (so it's not a video I can or need to embed).

The problem is that the video won't play - I can see the video preview image with a click icon, but clicking it has no response. 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);
    }
}
Amit
  • 1,174
  • 2
  • 15
  • 22
  • You can use embed code for this maybe. – Orhun Mert Simsek Jun 02 '12 at 10:01
  • check the link given at my answer at http://stackoverflow.com/questions/10208439/html5-video-doesnt-play-with-android/10209684#10209684 and download source using svn in which custome webview is used and which works fine – Khan Jun 02 '12 at 10:03

1 Answers1

5
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 doent work then try the 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;
             }
             }
         });
     }

 } 
Shankar Agarwal
  • 34,573
  • 7
  • 66
  • 64
  • I think that the second example isn't relevant, because I'm not directly opening the YouTube url. The first one helped me realize that I should remove the following line from my code - `webview.setWebViewClient(new WebViewClient());` - and once I did that, the video worked (after asking to select what should be used to display it, which is fine by me). – Amit Jun 02 '12 at 11:14