SJSSoft
SJSSoft

Reputation: 743

Play RTSP streaming in an Android application

I am trying to develop an Android based application, which can play video from a live stream. This live stream is produced using Wowza Media Server.

The URL is:

rtsp://tv.hindiworldtv.com:1935/live/getpun

I have tried following code in ecliplse:

package com.kalloh.wpa;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.Bundle;
import android.view.Window;
import android.widget.MediaController;
import android.widget.VideoView;


public class a extends Activity {

    VideoView videoView;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

        //Create a VideoView widget in the layout file
        //use setContentView method to set content of the activity to the layout file which contains videoView
        this.setContentView(R.layout.videoplayer);

        videoView = (VideoView)this.findViewById(R.id.videoView);

        //add controls to a MediaPlayer like play, pause.
        MediaController mc = new MediaController(this);
        videoView.setMediaController(mc);

        //Set the path of Video or URI
        videoView.setVideoURI(Uri.parse("rtsp://tv.hindiworldtv.com:1935/live/getpnj"));
        //

        //Set the focus
        videoView.requestFocus();
    }
}

At first, it was not working.

Now it started working, but it stops after 20 to 30 seconds. How can I fix this problem?

Upvotes: 36

Views: 106333

Answers (6)

mmdreza baqalpour
mmdreza baqalpour

Reputation: 1403

I was reading and researching about this subject for about a whole month and I used the VLC library to play RTSP streams from the camera although it works fine the problem with this library was the latency it had. I needed a library to play the stream in real-time so we were testing Gstreamer on Linux and Nvidia board it works fine with no latency and I managed to rebuild the Gstreamer library on my application and it works fine and it is so powerful. The Gstreamer Library

Upvotes: 0

mmdreza baqalpour
mmdreza baqalpour

Reputation: 1403

I searched and tried a lot of codes to play RTSP on Android And finally, I found this library. Hope this helps for whom looking for this kind of RTSP Player using Vlc

Upvotes: 0

Jorgesys
Jorgesys

Reputation: 126445

Using VideoView is a good solution, but we can also use the native player to play RTSP. This is an example:

if (movieurl.startsWith("rtsp://")) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(movieurl));
    startActivity(intent);
}

Bear in mind your media must be created with Android Supported Media Formats (codecs).

Upvotes: 13

Murali
Murali

Reputation: 500

I also had the same problem in ICS 4.x. Also, you can check whether your stream URL is working properly or not.

Also check your code with this sample URL.

Upvotes: 9

SJSSoft
SJSSoft

Reputation: 743

I found the solution. Transmission should be within the preferred setting by Android. For more details, see Supported Media Formats.

Upvotes: -3

hungson175
hungson175

Reputation: 4483

I had the same problem with Galaxy Note N7000 (ICS 4.0.3) and VLC 2.0.2 - the video dies after 60 seconds. But when I turn to VLC media player 1.1.4, everything just works well!

So sometimes it depends on the media server. You can try RTSP from YouTube (go to m.youtube.com and then right click on some video -> copy location link -> that is the RTSP link you need).

Upvotes: 0

Related Questions