简体   繁体   English

如何使用exoplayer流式传输rtsp url?

[英]how to stream rtsp url using exoplayer?

I want to stream rtsp video using exoplayer.我想使用 exoplayer 流式传输 rtsp 视频。 I am using ExoMedia library which is an An Android ExoPlayer wrapper.我正在使用ExoMedia 库,它是一个 Android ExoPlayer 包装器。 I have search on stackoverflow but I didn't find any good answer.我在 stackoverflow 上搜索过,但没有找到任何好的答案。 After some google search I found that exoplayer does not support rtsp stream issue 55 .经过一些谷歌搜索,我发现 exoplayer 不支持 rtsp 流问题 55 Is there any way to stream rtsp url using exoplayer?有没有办法使用exoplayer流式传输rtsp url? 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) 

Now ExoPlayer has support RTSP - https://github.com/google/ExoPlayer/pull/3854现在 ExoPlayer 已经支持 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您也可以按照 rtsp 查看示例应用程序 - https://github.com/google/ExoPlayer/pull/3854#issuecomment-377010803

Now exoplayer supports RTSP streaming.现在 exoplayer 支持 RTSP 流。

Refer to link : github.com/google/ExoPlayer参考链接:github.com/google/ExoPlayer

Actually current version of ExoPlayer doesn't support RTSP.实际上当前版本的 ExoPlayer 不支持 RTSP。 But as indicated in the issue issue 55 there's an active pull request #3854 to add this support.但是正如问题 55 中所指出的,有一个主动拉取请求#3854来添加此支持。

In the meantime, you can clone the original authors exoplayer fork which does support RTSP (branch dev-v2-rtsp):同时,您可以克隆支持 RTSP 的原作者exoplayer fork (分支 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.作者正在积极解决许多用户报告的问题,我希望 RTSP 支持在某个时候成为官方 exoplayer 的一部分。

ExoPlayer sort of has support for RTSP in the pull request (you have to grab a local copy, as it's not merged yet.) ExoPlayer 在拉取请求中支持 RTSP(您必须获取本地副本,因为它尚未合并。)

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.我在库中发现并修复了一个小错误(一个衬垫)(如果您查看拉取请求评论,我注意到了它的位置)但是对于大多数想要使用 Internet 网络摄像头之类的东西的用户来说,更大的问题是拉取请求中的当前代码库不处理 TCP 流——只有 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!)这意味着如果任何一端都在防火墙或其他 NAT 实例后面,它就不会工作,这对于移动网络上的任何用户和 WiFi 上的许多用户都是这种情况(特别是如果摄像头是隔离的,他们应该因为他们是出了名的不安全!)

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....我之前没有深入研究过 ExoPlayer 代码,要理解的东西很多....

现在 Exoplayer 从2.14.0版本开始正式支持 RTSP 更多细节在这里

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.我认为这反映了 RTSP 是一个功能丰富的规范,以及相关的 RTP 传输具有多种选择。

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.根据我的经验,ExoPlayer 可能会播放一个 URL,如果没有,那么 VLC 播放器 sdk 仍然可以播放它。 I have not see the reveres case - ie something that VLC can't play that ExoPlayer can, but this may quite possibly be the case also.我还没有看到 reveres 的情况 - 即 VLC 不能播放 ExoPlayer 可以播放的东西,但这很可能也是这种情况。

The approach I would take for a new project is:我为新项目采取的方法是:

  1. Test the URL on VLC player on a laptop first.首先在笔记本电脑上测试 VLC 播放器上的 URL。
  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如果上述方法有效,请在 Android 上的 VLC 播放器上测试 URL: 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如果上述方法有效,则通过将 URL 添加到测试播放器中的 ExoPlater 演示媒体并在那里测试: 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如果上述工作,你可能很高兴 - 如果没有,它在 VLC 播放器中工作,然后考虑在你的应用程序中使用 VLC 播放器: https : //code.videolan.org/videolan/libvlc-android-samples

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM