Wednesday, July 27, 2011

Video Streaming On Android

Despite being so simple and easy to develop applications on Android, it's still a tough job to stream a YouTube video. On a requirement of video streaming, I began my search, googled through various sites and blogs but was unsuccessful, and while m writing, i still i don't know the solution. Although I found some solutions.

The first solution that I found for video was, to play the video through the built-in YouTube app or through browser. But this wasn't the desired, as by using this method the control would go to the external app or the browser.
The code for using this approach is here..........

Intent myIntent = new Intent(Intent.ACTION_VIEW);
myIntent.setData(Uri.parse("http://www.youtube.com/watch?v=cxLG2wtE7TM"));
startActivityForResult(myIntent,0);

The other solution was to get the video manually from YouTube and then place it on a Web Server(like Tomcat). This way we could play the video in VideoView by setting the url in one of videoview's method as given here...........

videoView.setMediaController(new MediaController(this));
videoView.setVideoURI(Uri.parse(URL_VIDEO));
videoView.requestFocus();
videoView.start();

This way the video plays like charm, but then i don't know if it's the correct approach or what................

The third option I thought of was, instead of streaming the video every time through HTTP(which indirectly downloads the video and then plays it) I could download the video once and store it on SDcard, later whenever required I could play it through my application. This would save up the cost of network usage and also speed up the video playing except for the time spent at first download. Also it must be noted that if the video being played does not change frequently only then it should be downloaded else not.

This is all I have to say about video streaming in android................
Keeping my search on for Streaming YouTube videos .................

No comments:

Post a Comment