使用 eclipse 将 youtube 视频嵌入到 android 应用程序中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5798595/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Embedding a youtube video into android app using eclipse?
提问by Derek S
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.
我正在尝试弄清楚如何使用 eclipse 将 youtube 视频嵌入到 android 中。我更喜欢使用 chromeless 播放器,但目前没有必要。
Any help on how to do this would be greatly appreciated.
任何有关如何做到这一点的帮助将不胜感激。
回答by Trasplazio Garzuglio
The easiest way to embed a Youtube video is to use an intent to fire the Youtube application, like this:
嵌入 Youtube 视频的最简单方法是使用 Intent 来触发 Youtube 应用程序,如下所示:
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);
回答by sani_ok
YouTube API for Android is availible now. Following this link, you will find a sample how to use YouTube API under Android.
Android 版 YouTube API 现已推出。在此链接之后,您将找到如何在 Android 下使用 YouTube API 的示例。
Using YouTubePlayerView you can play video from youtube in your activity. But it is not possible to change default controls.
使用 YouTubePlayerView,您可以在您的活动中播放来自 youtube 的视频。但无法更改默认控件。
回答by stevyhacker
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 并仅使用该 youtube 视频的 iframe 加载它。
WebView webview;
webview.getSettings().setJavaScriptEnabled(true);
webview.loadData("<iframe src=\"http://www.youtube.com/watch?v=hZ4sDn89P04\"></iframe>","text/html","utf-8");