Show your RTSP video in Android with VLC

If you have developed an Android app with video streaming, I’m sure you notice that Android use a pre-load of video buffer that fills in 10 seconds. This delay is hardcode in the source code. It’s very hard create a real time app to show video with this delay.

There are several solutions out of android to show video streaming. Some of them provide SDK to develop. But if you don’t want develop to other SDK, you can use VLC for android. Thanks to the intent’s communication of Android, we can interact with VLC Android app.

1
2
3
4
Intent i = new Intent("org.videolan.vlc.VLCApplication.gui.video.VideoPlayerActivity");
i.setAction(Intent.ACTION_VIEW);		
i.setData(Uri.parse("rtsp://your_url:554/"));
startActivity(i);

If you are interested to know how I get these lines, keep reading.
Maybe, you ask yourself “how do I find the correct name of activity and parameters?”. Well, this is not magic. In general, if you want interact with a specific android application and you have access to source code (FLOSS blessed!), follow these steps.

1. Download the source code

In our case, we download VLC for android source code by git

1
git clone git://git.videolan.org/vlc-ports/android.git

2. Let’s see AndroidManifest.xml file

Take a moment to see and analyze the AndrodManifest.xml file of VLC for Android project. Quickly you see that exist one activity declared in the manifest that have a lot of intent-filter. The activity is “.gui.video.VideoPlayerActivity”. If you keep looking, you notice that one intent-filter declared the protocols that support this activity and the action of the intent

1
2
3
4
5
6
   <!--  This filter captures protocols without type info  -->
 
       <data></data>
       <data></data>
       <data></data>
       <data></data>

So, we have the name of the activity (VideoPlayerActivity) and the action of the intent (action.VIEW).

3. Let’s see JAVA source code

Well, just we have to know how send the data. In our case, we want to send the URI that represents the url of video rtsp. Normally, the data in the intents is sent using setData method.

1
i.setData(Uri.parse("rtsp://your_url:5554/"));

But it’s possible that the developer of the other application use the putExtra methods to send the data. Also, you have to know the name of param.

1
i.putExtra("URL_STREAMING", Uri.parse("rtsp://your_url:5554/"));

Let’s see how VLC for Android app implement this feature. Take a look at VideoPlayerActivity file. If you search by getIntent() (you know, it’s the method that android developers uses to know the Intent sent), you get the load() method. If you pay attention in this method, you can see the following lines that say you how the date is sent.

1
2
Cursor cursor = managedQuery(getIntent().getData(), new String[]{ MediaStore.Video.Media.DATA }, null, null, null);
mLocation = getIntent().getData().getPath();

Also, you can see they use getExtras() to get optional parameters in the intent call.

1
itemTitle = getIntent().getExtras().getString("itemTitle");

So, you can send the uri of rtsp video and the title that you want VLC android show in the screen. The source code would:

1
2
3
4
5
Intent i = new Intent("org.videolan.vlc.VLCApplication.gui.video.VideoPlayerActivity");
i.setAction(Intent.ACTION_VIEW);		
i.setData(Uri.parse("rtsp://your_url:5554/"));
i.putExtra("itemTitle", "your video title");
startActivity(i);

As a general rule, if you get access to source code or at least access to AndroidManifest file you’ll know how interact with this android application.

UPDATED: 11/07/2013

The new version of VLC Android app requires the following source code to interact:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
private void launchVLC (String url)
{
	try{
		Intent i = new Intent(Intent.ACTION_VIEW);
		i.setComponent(new ComponentName("org.videolan.vlc.betav7neon", "org.videolan.vlc.betav7neon.gui.video.VideoPlayerActivity"));			
		i.setData(Uri.parse(url));			
		startActivity(i);
	} 
	catch (ActivityNotFoundException e){
		Uri uri = Uri.parse("http://play.google.com/store/apps/details?id=org.videolan.vlc.betav7neon");
		Intent intent = new Intent (Intent.ACTION_VIEW, uri); 
		startActivity(intent);
	}		
}
facebooktwittergoogle_pluslinkedinmailby feather
This entry was posted in android, floss. Bookmark the permalink.

3 Responses to Show your RTSP video in Android with VLC

  1. Chris says:

    HI, can I use this code to stream via HTTP?

  2. Nirav says:

    hi..i am developing an RTSP streaming application. I have authenticated RTSP. i have downloaded Vlc-android app from git hub. I want to display authenticateed RTSP in vlc-android. How can i use it??

  3. Nirav says:

    Nice article

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>