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.
  • k

    Does it work with rtmp?

    • G

      Yes it does.

  • kishan

    I want to stream live video from justin.tv can i use Vitamio for this

    • amands_1

      Vitamio doesn’t support flash video, so we can’t play justin.tv live stream with vitamio.

      • kishan

        oh k. But do u know what plugin to use instead of vitamio for android to stream justin.tv ???? Thanks in advance…..

  • Ahmet Ertaş

    I’m trying to get stream from an IP Camera and stream it via Android. And this stream is .asf . Can I handle it with Vitamio ? Thanks in advance

  • Francesco

    Hello i have put the code in mainactivity but i have just one Error:
    (“”)
    I do like this:
    (“myurl”) or () but the same give me error. Can you help me?