36

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
SJSSoft
  • 723
  • 2
  • 10
  • 28

6 Answers6

13

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).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jorgesys
  • 124,308
  • 23
  • 334
  • 268
  • 3
    i don't get this, will this code open an installed app or is your app the video-displaying app? – user1767754 Nov 17 '14 at 23:33
  • If I stream within my app (with dvblast for example), when I open ThirdApp (according to your solution), My current app goes to background and it doesn't broadcast anymore; so third opened app can't receive anything. How to handle this situation? – Dr.jacky Oct 03 '15 at 05:48
  • @Mr.Hyde: Maybe your broadcasting app should use a Service, so that it will keep running in the background? – LarsH Nov 28 '16 at 17:32
  • which one is better? playing through "Native player" or through "video view" – Prabs Dec 01 '17 at 07:26
9

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Murali
  • 500
  • 5
  • 22
0

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).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
hungson175
  • 4,373
  • 6
  • 22
  • 21
  • I found the solution. Transmission should be within preffered setting by Android. for more details, plz check @ http://developer.android.com/guide/appendix/media-formats.html – SJSSoft Oct 11 '12 at 06:56
  • The native RTSP stack may not be sending GET_PARAMETER to keep the connection alive... check out http://net7mma.codeplex.com/ – Jay Jun 24 '16 at 22:02
0

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

mmdreza baqalpour
  • 1,106
  • 9
  • 18
0

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

mmdreza baqalpour
  • 1,106
  • 9
  • 18
-3

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
SJSSoft
  • 723
  • 2
  • 10
  • 28