UDP Video Streaming on Android(Android 上的 UDP 视频流)
问题描述
我有一个 Android 项目,我需要构建一个客户端应用程序来接收 UDP 或 RTP 单播视频流并播放它们.不幸的是,我似乎无法让这个工作,并且已经广泛搜索解决方案!
I have an Android project where I need to build a client app to receive UDP or RTP unicast video streams and play them back. Unfortunately, I cannot seem to get this working and have searched extensively for a solution!
我正在 Xoom (Android 3.2) 和 Nexus S (Android 2.3.6) 上进行测试,并且知道它们可以在使用 MX Player(第三方媒体播放器应用)作为客户端,但我无法让原生媒体播放器播放内容.我尝试使用简单的 VideoView 和 MediaPlayer,但都失败并出现相同的错误代码,我真的找不到任何有用的信息.
I have being testing on a Xoom (Android 3.2) and a Nexus S (Android 2.3.6) and know that they can play the content when using MX Player (a third-party media player app) as the client but I can't get the native media player to play back the content. I have tried using both a simple VideoView and a MediaPlayer but both fail with the same error code and I can't really find any helpful information on.
视频是使用 aac 音频进行 H.264 编码的.
The video is H.264 encoded with aac audio.
另外,服务器是第三方的解决方案,我无权访问(除了指定 udp 或 rtp),但正如我所说,使用 MX Player 时,可以播放流.
Also, the server is a solution by a third-party which I have no access to (other than to specify udp or rtp) but as I said, when using MX Player, the streams can be played.
这是我的代码的媒体播放器部分:
Here is the media player portion of my code:
public class Main extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
MediaPlayer player = new MediaPlayer();
SurfaceView surface = (SurfaceView) findViewById(R.id.video);
player.setDisplay(surface.getHolder());
player.setDataSource(this, Uri.parse("udp://192.168.0.78:1234"));
player.prepare();
player.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
Log.d("SimpleVideoPlayer", "Starting player");
mp.start();
}
});
player.setOnErrorListener(new OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
Log.d("SimpleVideoPlayer", "error with code: " + what);
return false;
}
});
}catch(Exception e) {
e.printStackTrace();
}
}
我收到的错误是:
11-29 15:44:14.660: D/MediaPlayer(15451): Couldn't open file on client side, trying server side
11-29 15:44:14.670: E/MediaPlayer(15451): error (1, -2147483648)
11-29 15:44:14.670: W/System.err(15451): java.io.IOException: Prepare failed.: status=0x1
11-29 15:44:14.670: W/System.err(15451): at android.media.MediaPlayer.prepare(Native Method)
11-29 15:44:14.670: W/System.err(15451): at com.android.vidplayer.Main.onCreate(Main.java:26)
11-29 15:44:14.670: W/System.err(15451): at android.app.Activity.performCreate(Activity.java:4397)
11-29 15:44:14.670: W/System.err(15451): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
11-29 15:44:14.670: W/System.err(15451): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1804)
11-29 15:44:14.670: W/System.err(15451): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1856)
11-29 15:44:14.670: W/System.err(15451): at android.app.ActivityThread.access$500(ActivityThread.java:125)
11-29 15:44:14.670: W/System.err(15451): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1049)
11-29 15:44:14.670: W/System.err(15451): at android.os.Handler.dispatchMessage(Handler.java:99)
11-29 15:44:14.670: W/System.err(15451): at android.os.Looper.loop(Looper.java:132)
11-29 15:44:14.670: W/System.err(15451): at android.app.ActivityThread.main(ActivityThread.java:4157)
11-29 15:44:14.670: W/System.err(15451): at java.lang.reflect.Method.invokeNative(Native Method)
11-29 15:44:14.670: W/System.err(15451): at java.lang.reflect.Method.invoke(Method.java:491)
11-29 15:44:14.670: W/System.err(15451): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
11-29 15:44:14.670: W/System.err(15451): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
11-29 15:44:14.670: W/System.err(15451): at dalvik.system.NativeStart.main(Native Method)
我也设置了互联网权限.
I have set the Internet permissions also.
请问大家有什么建议吗??我在任何地方都找不到任何有用的信息.
Does anybody have any suggestions please?? I can't find any helpful info anywhere.
谢谢.
推荐答案
我不确定 Android 本身是否支持 UDP,因为它没有在网络协议中列出
I'm not sure Android natively supports UDP as it's not listed in the Network Protocols
http://developer.android.com/guide/appendix/media-格式.html
许多第 3 方媒体播放器都基于 FFMPEG 库.您可能希望在您的项目中使用 FFMPEG,尽管这本身就是一项任务.
Many 3rd party mediaplayers are based upon the FFMPEG libraries. You may want to use FFMPEG in your project although that's a task in its own.
这篇关于Android 上的 UDP 视频流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android 上的 UDP 视频流
基础教程推荐
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01