开发者

Embedding a youtube video into android app using eclipse?

开发者 https://www.devze.com 2023-03-01 02:40 出处:网络
I\'m trying to figure out how to embed youtube 开发者_开发知识库videos into android using eclipse.I would prefer to use the chromeless player, but at this point it\'s not necessary.

I'm trying to figure out how to embed youtube 开发者_开发知识库videos into android using eclipse. I would prefer to use the chromeless player, but at this point it's not necessary.

Any help on how to do this would be greatly appreciated.


The easiest way to embed a Youtube video is to use an intent to fire the Youtube application, like this:

String video_path = "http://www.youtube.com/watch?v=opZ69P-0Jbc";
Uri uri = Uri.parse(video_path);

// With this line the Youtube application, if installed, will launch immediately.
// Without it you will be prompted with a list of the application to choose.
uri = Uri.parse("vnd.youtube:"  + uri.getQueryParameter("v"));

Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);


YouTube API for Android is availible now. Following this link, you will find a sample how to use YouTube API under Android.

Using YouTubePlayerView you can play video from youtube in your activity. But it is not possible to change default controls.


If you want to play the video from inside the application to really embed it you can use WebView and load it with just iframe of that youtube video.

WebView webview;
webview.getSettings().setJavaScriptEnabled(true);
webview.loadData("<iframe src=\"http://www.youtube.com/watch?v=hZ4sDn89P04\"></iframe>","text/html","utf-8");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号