How to play YouTube video in WebView on Google Glass

前端 未结 1 565
情歌与酒
情歌与酒 2021-02-10 00:47

I have code like this:

setContentView(R.layout.webview);       
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true)         


        
1条回答
  •  无人共我
    2021-02-10 01:43

    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.

    0 讨论(0)
提交回复
热议问题