Archive for the ‘Streaming’ Category

Streaming Videos in an Android Application

The blog details on how we can stream videos in an android application. There are basically two parts two parts to the problem:
  1. A streaming server like adobe flash media which can deliver a video stream
  2. Playing the video progressively in your android application with help of a video player
The blog assumes that you already have a file uploaded at some place from where the player can pick up the file to play. The simple and the easiest solution is to use the android VideoView but the problem with the VideoView is it requires the whole file to be downloaded before starts playing. It can be very annoying to serve the videos like this in a real time production application. If however, you are happy with this behavior, you can skip the rest of the blog. Vitamio player Vitamio for android is an android library with a VideoView similar to android’s native VideoView. Vitamio’s VideoView can be used to play or stream the videos. To integrate vitamio,  its library for android needs to be included in the android project. The library is available at the following URL: https://github.com/yixia/VitamioBundle Using Vitamio with an existing Android project After downloading the Vitamio bundle add it into your android project as library. We will now start to build a simple Vitamio VideoView to play the videos Layout In layout xml file add the following lines to add videoView

<io.vov.vitamio.widget.VideoView
 android:id="@+id/video_view"
 android:layout_width="match_parent"
 android:layout_height="match_parent" >

Activity In your activity file import vitamio’s videoView (io.vov.vitamio.widget.VideoView) instead of android native VideoView (android.widget.VideoView). The following sample code demonstrates how you can create a VideoView to stream a video within the Vitamio VideoView.

VideoView mVideoView = (VideoView)findViewById(R.id.video_view);

 //Setting video path(url)
 videoView = mVideoView.setVideoPath(“<Video url>”);

 //Setting main focus on video view
 mVideoView.requestFocus();
 mVideoView.start();

 //Initializing the video player’s media controller.
 MediaController controller = new MediaController(this);

 //Binding media controller with VideoView

 mVideoView.setMediaController(controller);

 //Registering a callback to be invoked when the media file is loaded and ready to go.
 mVideoView.setOnPreparedListener(new OnPreparedListener() {

 @Override
 public void onPrepared(MediaPlayer arg0) {
 //Starting the player after getting information from url.
 mVideoView.start();
 }
 });

Thats it !! You are now ready to stream videos within the vitamio video viewer. There are a lot of options that you can explore within the viewer in the vitamio documentation which is available on their site.