Search code examples
google-gdk

How to play YouTube video in WebView on Google Glass


I have code like this:

setContentView(R.layout.webview);       
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("https://www.youtube.com/watch?v=_Z5-P9v3F8w");

It'll show the youtube video with the Play button, but none of the Glass gesture can make the video play. Any ideas? Thanks!


Solution

  • Finally figured out how to play Youtube video on Glass!

    Intent i = new Intent();
    i.setAction("com.google.glass.action.VIDEOPLAYER");
    i.putExtra("video_url", "https://m.youtube.com/watch?v=5bWSgFnoCOk"); 
    startActivity(i);    
    

    Using WebView can't play the video, using VideoView can only play local MP4 or streaming MP4 (there's some way to hack the MP4 link for a Youtube video, but not reliable). Also, using VideoView can only pause/play the video, but not fast forward or backward. Using the com.google.glass.action.VIDEOPLAYER above solves all the problems WebView and VideoView have.