某处在我的Android应用程序,我想打一个YouTube视频, 在我的活动,在一个小图。 我想用这样做的 VideoView ,但至今没有运气。
Somewhere in my Android app I would like to play a youtube video, in my activity, in a small view. I'm trying to do this using VideoView, but no luck so far..
我写了一个简单的活动,这是我的code到目前为止:
I wrote a simple activity, here is my code so far:
public class MainView extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView videoView = (VideoView) findViewById(R.id.VideoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
/*working good but IT'S NOT youtube*/ //Uri video = Uri.parse("http://commonsware.com/misc/test2.3gp");
/*NOT WORKING*/ //Uri video = Uri.parse("http://www.youtube.com/watch?v=hLQl3WQQoQ0&ob=av2e");
/*NOT WORKING (RTSP)*/ //Uri video = U-ri.parse("http://m.youtube.com/watch?gl=IL&hl=en&client=mv-google&feature=grec_mobile&v=6WHRxXY67UA");
/*NOT WORKING (RTSP)*/Uri video = Uri.parse("http://m.youtube.com/watch?gl=IL&hl=en&client=mv-google&v=wWub_aXPCVg");
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
}
}
这可能吗? 是否有任何其他的SDK组件,能做到吗? 任何想法?
is it possible? is there any other SDK component that can do that? any ideas?
谢谢, Amitos80
Thanks, Amitos80
谷歌都在未来数月,到2012年年底发布了YouTube的Android组件,所以希望。
Google are releasing android components for YouTube "in the coming months", so hopefully by the end of 2012.
我在做什么,在此期间可使用具有loadData()一个web视图,并通过在iframe作为YouTube的API页面上的说明。该IFRAME是非常有限的(大部分参数甚至不工作,如控制= 0),因此,如果您需要更多像控制视图,然后使用JavaScript API,然后嵌入的JavaScript中传递到loadData HTML的灵活性。
What I am doing in the meantime is using a WebView with loadData(), and passing in an IFrame as stated on the YoUTube API page. The Iframe is quite limited (most parameters don't even work, like controls=0), so if you need more flexibility like controlling the view then use the JavaScript API and then embed the JavaScript in the HTMl you pass into loadData.
我试过了媒体控制器并不能得到它的工作,即使YouTube的使用它在那里自己的应用程序。
I tried the Media Controller and couldn't get it to work, even though YouTube use it in there own app.
另外要尝试,我没有得到周围。是使用谷歌搜索的API。您可以指定一个YouTube视频,它会给你的URL的缩略图,视频等,这样你可以得到的原始文件(www.youtube.com/...../..../myfile.3gp ),而不是调用一个网页。然后,这些可能是可装载在的MediaController。
The other thing to try which i didn't get around to. Is to use the google search apis. You can specify a YouTube video and it will give you the URL's to the thumbnails, videos etc. This way you can get to the raw files (www.youtube.com/...../..../myfile.3gp) rather than calling a webpage. These might then be loadable in the MediaController.