简体   繁体   English

Android上的UDP视频流

[英]UDP Video Streaming on Android

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. 我有一个Android项目,我需要构建一个客户端应用程序来接收UDP或RTP单播视频流并播放它们。 Unfortunately, I cannot seem to get this working and have searched extensively for a solution! 不幸的是,我似乎无法让这个工作,并广泛搜索解决方案!

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. 我正在测试Xoom(Android 3.2)和Nexus S(Android 2.3.6)并且知道他们可以在使用MX Player (第三方媒体播放器应用程序)作为客户端时播放内容,但我不能让本机媒体播放器播放内容。 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. 我尝试过使用简单的VideoView和MediaPlayer,但都失败了相同的错误代码,我真的找不到任何有用的信息。

The video is H.264 encoded with aac audio. 该视频采用带有aac音频的H.264编码。

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. 此外,服务器是我无法访问的第三方解决方案(除了指定udp或rtp),但正如我所说,使用MX Player时,可以播放流。

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();
    }
}

The error I'm receiving is: 我收到的错误是:

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. 我也设置了Internet权限。

Does anybody have any suggestions please?? 有人有什么建议吗? I can't find any helpful info anywhere. 我在任何地方都找不到任何有用的信息。

Thanks. 谢谢。

I'm not sure Android natively supports UDP as it's not listed in the Network Protocols 我不确定Android本身是否支持UDP,因为它没有在网络协议中列出

http://developer.android.com/guide/appendix/media-formats.html http://developer.android.com/guide/appendix/media-formats.html

Many 3rd party mediaplayers are based upon the FFMPEG libraries. 许多第三方媒体播放器都基于FFMPEG库。 You may want to use FFMPEG in your project although that's a task in its own. 您可能希望在项目中使用FFMPEG,尽管这是一项任务。

You can also stream via udp:// using the Vitamio library (it uses ffmpeg behind the scenes). 您也可以使用Vitamio库通过udp://进行流式传输(它在后台使用ffmpeg)。 http://www.vitamio.org/en/ http://www.vitamio.org/en/

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

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