在 Android 上显示实时 UDP 或 RTP 流(多播)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11452865/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:42:43  来源:igfitidea点击:

Displaying live UDP or RTP stream (multicast) on Android

androidudpvideo-streamingrtp

提问by Thibault

I am new to Android development since a few weeks, and I need to write an app that can display the user a live stream multicasted in UDP or RDP. The stream is located at an address such as "rtp://230.0.0.11:1234", and is emitted by WIFI thanks to this module : http://www.ikusi.es/public/ctrl_public_prod.php?accion=verProducto&id_familia=34&id_gama=186&id_producto=351

几周以来,我是 Android 开发的新手,我需要编写一个应用程序,该应用程序可以向用户显示以 UDP 或 RDP 多播的实时流。该流位于诸如“rtp://230.0.0.11:1234”之类的地址,并且由于此模块由 WIFI 发出:http://www.ikusi.es/public/ctrl_public_prod.php?accion=verProducto&id_familia =34&id_gama=186&id_producto=351

I already tried to read it from a player (Daroon player, from PlayStore), and it worked well, so I assume that my foolowing problem is not due to the broadcast.

我已经尝试从播放器(来自 PlayStore 的 Daroon 播放器)读取它,并且效果很好,所以我认为我的愚蠢问题不是由于广播引起的。

I saw that it is possible to display video content to the user by different ways :

我看到可以通过不同的方式向用户显示视频内容:

  • Using a new Intent with an ACTION_VIEW, and Android selects an app that can view the content;

  • Using the MediaPlayer class and VideoView.

  • 使用带有 ACTION_VIEW 的新 Intent,Android 选择一个可以查看内容的应用程序;

  • 使用 MediaPlayer 类和 VideoView。

I have two issues, let us start with the most important : - For both solution above, there is an issue : I read everywhere that MediaPlayer only support http/s and rtsp protocols, is that right? And for the action view here is what I tried before :

我有两个问题,让我们从最重要的开始: - 对于上面的两个解决方案,有一个问题:我到处都读到 MediaPlayer 只支持 http/s 和 rtsp 协议,对吗?对于这里的动作视图,这是我之前尝试过的:

    Uri streamURL = Uri.parse("rtp://230.0.0.11:1234");
    Intent streamIntent = new Intent(Intent.ACTION_VIEW);
    streamIntent.setData(streamURL);
//  streamIntent.setDataAndType(streamURL,"video/*");   
    startActivity(streamIntent);

Here is the LogCat :

这是 LogCat :

07-11 00:25:58.119: D/AndroidRuntime(2659): Shutting down VM
07-11 00:25:58.119: W/dalvikvm(2659): threadid=1: thread exiting with uncaught exception (group=0x40015560)
07-11 00:25:58.129: E/AndroidRuntime(2659): FATAL EXCEPTION: main
07-11 00:25:58.129: E/AndroidRuntime(2659): java.lang.IllegalStateException: Could not execute method of the activity
07-11 00:25:58.129: E/AndroidRuntime(2659):     at android.view.View.onClick(View.java:2144)
07-11 00:25:58.129: E/AndroidRuntime(2659):     at android.view.View.performClick(View.java:2485)
07-11 00:25:58.129: E/AndroidRuntime(2659):     at android.view.View$PerformClick.run(View.java:9080)
07-11 00:25:58.129: E/AndroidRuntime(2659):     at android.os.Handler.handleCallback(Handler.java:587)
07-11 00:25:58.129: E/AndroidRuntime(2659):     at android.os.Handler.dispatchMessage(Handler.java:92)
07-11 00:25:58.129: E/AndroidRuntime(2659):     at android.os.Looper.loop(Looper.java:123)
07-11 00:25:58.129: E/AndroidRuntime(2659):     at android.app.ActivityThread.main(ActivityThread.java:3683)
07-11 00:25:58.129: E/AndroidRuntime(2659):     at java.lang.reflect.Method.invokeNative(Native Method)
07-11 00:25:58.129: E/AndroidRuntime(2659):     at java.lang.reflect.Method.invoke(Method.java:507)
07-11 00:25:58.129: E/AndroidRuntime(2659):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-11 00:25:58.129: E/AndroidRuntime(2659):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-11 00:25:58.129: E/AndroidRuntime(2659):     at dalvik.system.NativeStart.main(Native Method)
07-11 00:25:58.129: E/AndroidRuntime(2659): Caused by: java.lang.reflect.InvocationTargetException
07-11 00:25:58.129: E/AndroidRuntime(2659):     at java.lang.reflect.Method.invokeNative(Native Method)
07-11 00:25:58.129: E/AndroidRuntime(2659):     at java.lang.reflect.Method.invoke(Method.java:507)
07-11 00:25:58.129: E/AndroidRuntime(2659):     at android.view.View.onClick(View.java:2139)
07-11 00:25:58.129: E/AndroidRuntime(2659):     ... 11 more
07-11 00:25:58.129: E/AndroidRuntime(2659): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=rtp://230.0.0.11:1234 }
07-11 00:25:58.129: E/AndroidRuntime(2659):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409)
07-11 00:25:58.129: E/AndroidRuntime(2659):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
07-11 00:25:58.129: E/AndroidRuntime(2659):     at android.app.Activity.startActivityForResult(Activity.java:2827)
07-11 00:25:58.129: E/AndroidRuntime(2659):     at android.app.Activity.startActivity(Activity.java:2933)
07-11 00:25:58.129: E/AndroidRuntime(2659):     at fr.infosat.tvreplay.MainActivity.listStream(MainActivity.java:35)
07-11 00:25:58.129: E/AndroidRuntime(2659):     ... 14 more
07-11 00:26:00.079: I/Process(2659): Sending signal. PID: 2659 SIG: 9

My understanding is that the error InvocationTargetException, usually due to error on class names, cannot be resolved directly here, since I don't call any class in startActivity. However I think my syntax is not correct, maybe the method is not the right one to use. Of course if I uncomment the setDataAndType line, it displays the same error.

我的理解是,通常由于类名错误导致的错误 InvocationTargetException 无法在此处直接解决,因为我没有在 startActivity 中调用任何类。但是我认为我的语法不正确,也许该方法不适合使用。当然,如果我取消注释 setDataAndType 行,它会显示相同的错误。

I noticed the error come when I launch my implicit intent.

当我启动隐式意图时,我注意到错误出现。

  • My second problem is that Daroon Player works well on my set top box, I can see my stream on my TV. But when I try to launch it from Eclipse emulator, it doesn't play, even if I can play it from VLC... Is the emulator powerful enough to read those kind of stream?
  • 我的第二个问题是 Daroon Player 在我的机顶盒上运行良好,我可以在电视上看到我的流。但是当我尝试从 Eclipse 模拟器启动它时,它不会播放,即使我可以从 VLC 播放它......模拟器是否足够强大以读取这些流?

I hope that you have some clues on how to solve that! :)

我希望你有一些关于如何解决这个问题的线索!:)

采纳答案by chrulri

First, you get the exception because there is no app installed on your device which can handle such an rtp://url.

首先,您会收到异常,因为您的设备上没有安装可以处理此类rtp://url 的应用程序。

You may want to check the intent before you start it: queryIntentActivities(..)

您可能想在开始之前检查意图:queryIntentActivities(..)

Second, I think emulator is pretty slow compared to any available real device, you may not want to use emulator to test A/V streaming.

其次,我认为模拟器与任何可用的真实设备相比都非常慢,您可能不想使用模拟器来测试 A/V 流。

回答by Muthukumar Anbalagan

VLC Android SDK works really perfect in UDP/RTP

VLC Android SDK 在 UDP/RTP 中工作得非常完美

https://code.videolan.org/videolan/vlc-android

https://code.videolan.org/videolan/vlc-android

libvlc