问题
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.
回答1:
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);
回答2:
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.
回答3:
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");
来源:https://stackoverflow.com/questions/5798595/embedding-a-youtube-video-into-android-app-using-eclipse