Vikash Kumar Verma
Vikash Kumar Verma

Reputation: 1078

how to stream rtsp url using exoplayer?

I want to stream rtsp video using exoplayer. I am using ExoMedia library which is an An Android ExoPlayer wrapper. I have search on stackoverflow but I didn't find any good answer. After some google search I found that exoplayer does not support rtsp stream issue 55. Is there any way to stream rtsp url using exoplayer? Here is my code.

public class MainActivity extends AppCompatActivity implements OnPreparedListener{
    EMVideoView emPlayer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        playVideo();
    }


    private void playVideo() {
        emPlayer = (EMVideoView)findViewById(R.id.video_view);
        emPlayer.setOnPreparedListener(this);

        emPlayer.setVideoURI(Uri.parse("rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov"));
    }

    @Override
    public void onPrepared() {
        emPlayer.start();
        Log.v("TAG","video is playing");
    }
}

Here is my log

com.google.android.exoplayer.ExoPlaybackException: com.google.android.exoplayer.upstream.HttpDataSource$HttpDataSourceException: Unable to connect to rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov
           at com.google.android.exoplayer.SampleSourceTrackRenderer.maybeThrowError(SampleSourceTrackRenderer.java:262)
           at com.google.android.exoplayer.SampleSourceTrackRenderer.maybeThrowError(SampleSourceTrackRenderer.java:148)
           at com.google.android.exoplayer.ExoPlayerImplInternal.incrementalPrepareInternal(ExoPlayerImplInternal.java:273)
           at com.google.android.exoplayer.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:203)
           at android.os.Handler.dispatchMessage(Handler.java:98)
           at android.os.Looper.loop(Looper.java:135)
           at android.os.HandlerThread.run(HandlerThread.java:61)
           at com.google.android.exoplayer.util.PriorityHandlerThread.run(PriorityHandlerThread.java:40)
        Caused by: com.google.android.exoplayer.upstream.HttpDataSource$HttpDataSourceException: Unable to connect to rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov
           at com.google.android.exoplayer.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.java:191)
           at com.google.android.exoplayer.upstream.DefaultUriDataSource.open(DefaultUriDataSource.java:133)
           at com.google.android.exoplayer.extractor.ExtractorSampleSource$ExtractingLoadable.load(ExtractorSampleSource.java:823)
           at com.google.android.exoplayer.upstream.Loader$LoadTask.run(Loader.java:222)
           at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
           at java.util.concurrent.FutureTask.run(FutureTask.java:237)
           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
           at java.lang.Thread.run(Thread.java:818)
        Caused by: java.net.MalformedURLException: Unknown protocol: rtsp
           at java.net.URL.<init>(URL.java:182)
           at java.net.URL.<init>(URL.java:125)
           at com.google.android.exoplayer.upstream.DefaultHttpDataSource.makeConnection(DefaultHttpDataSource.java:330)
           at com.google.android.exoplayer.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.java:189)
           at com.google.android.exoplayer.upstream.DefaultUriDataSource.open(DefaultUriDataSource.java:133) 
           at com.google.android.exoplayer.extractor.ExtractorSampleSource$ExtractingLoadable.load(ExtractorSampleSource.java:823) 
           at com.google.android.exoplayer.upstream.Loader$LoadTask.run(Loader.java:222) 
           at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422) 
           at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
           at java.lang.Thread.run(Thread.java:818) 

Upvotes: 10

Views: 16533

Answers (6)

Mick
Mick

Reputation: 25471

This is an old question but it seems topical. From the history here it can be seen that it was not supported, was reported to be supported, then some still had problems and others found it worked.

I think this reflects RTSP being quite a feature rich spec, as well as the associated RTP transport having multiple options.

In my experience ExoPlayer may play a URL, and if it does not then the VLC player sdk may still be able to play it. I have not see the reveres case - i.e. something that VLC can't play that ExoPlayer can, but this may quite possibly be the case also.

The approach I would take for a new project is:

  1. Test the URL on VLC player on a laptop first.
  2. If the above works, test the URL on VLC player on Android: https://play.google.com/store/apps/details?id=org.videolan.vlc&hl=en_IE&gl=US
  3. If the above works then test by adding the URL into the ExoPlater demo media in the test player and test there: https://github.com/google/ExoPlayer/pull/3854#issuecomment-841167938
  4. If the above works, you are likely good to go - if not and it worked in VLC player then consider using the VLC player in your app instead: https://code.videolan.org/videolan/libvlc-android-samples

Upvotes: 0

siva
siva

Reputation: 1858

Now Exoplayer officially supports RTSP starting from version 2.14.0 More details here

Upvotes: 0

rkachach
rkachach

Reputation: 17345

Actually current version of ExoPlayer doesn't support RTSP. But as indicated in the issue issue 55 there's an active pull request #3854 to add this support.

In the meantime, you can clone the original authors exoplayer fork which does support RTSP (branch dev-v2-rtsp):

git clone -b dev-v2-rtsp https://github.com/tresvecesseis/ExoPlayer.git

I've tested it and it works perfectly. The authors are working actively to fix the issues reported by many users and I hope that RTSP support at some point becomes part of the official exoplayer.

Upvotes: 1

UserSharma
UserSharma

Reputation: 488

Now exoplayer supports RTSP streaming.

Refer to link : github.com/google/ExoPlayer

Upvotes: 1

Tickerguy
Tickerguy

Reputation: 111

ExoPlayer sort of has support for RTSP in the pull request (you have to grab a local copy, as it's not merged yet.)

There's a small bug (one liner) that I found and fixed in the libraries (if you look at the pull request commentary I noted where it is) but the bigger issue for most users that want to get at something like an Internet Webcam is that the current codebase that is in the pull request does not handle TCP streaming -- only UDP.

That means it won't work if either end is behind a firewall or other NAT instance, which is going to be the case for basically any user on a mobile network and many while on WiFi (especially if the cams are segregated, and they should be as they're notoriously insecure!)

I'm putting some effort into seeing if I can cobble up some patches to their patches, but it may be a while; I've not dug into the ExoPlayer code before, and there's a lot of it to understand....

Upvotes: 0

nicolas asinovich
nicolas asinovich

Reputation: 3511

Now ExoPlayer has support RTSP - https://github.com/google/ExoPlayer/pull/3854

Also you can follow to see example app with rtsp - https://github.com/google/ExoPlayer/pull/3854#issuecomment-377010803

Upvotes: 3

Related Questions