直播流视频从一个android手机到另一个无线网络 [英] Live-stream video from one android phone to another over WiFi

查看:194
本文介绍了直播流视频从一个android手机到另一个无线网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上搜索了几天了如何从Android手机实现视频流媒体功能,另一款Android手机通过WiFi连接,但我似乎无法找到任何有用的东西。我看了看在Android开发者的样本code,计算器,谷歌,Android的博客,但没有。所有我能看到的是某种形式的手机到桌面或者从桌面到手机解决方案,流媒体,但没有我可以在我的实现借款。

I have searched the internet for days now on how to implement a video streaming feature from an android phone to another android phone over a WiFi connection but I can't seem to find anything useful. I looked on android developers for sample code, stackoverflow, google, android blogs but nothing. All I can find are some sort of phone-to-desktop or desktop-to-phone solutions for streaming, but nothing that I can borrow in my implementation.

我需要控制使用一个Arduino ADK的机器人,所以我使用2部电话,其中一个将被安装在机器人装置和其他将来自机器人接收视频流。我提到这一点,因为我想实现的播出时间和收视时间之间的最小延迟。

I need to control a robot using an arduino ADK, so I am using 2 phones, one which will be mounted on the robot and another which will receive the video stream from the robot. I am mentioning this because I am trying to achieve the smallest delay between the broadcast time and the viewing time.

我写2应用程序,一个主应用程序来控制机器人(从手持电话),将控制从应用程序和接收流,第二个从应用程序将运行机器人拮据的手机上,控制电机/驱动器/流掌握应用程序。我不能使用第三方应用程序的不幸。我需要整合的视频流code到我的2个应用程序。

I am writing 2 apps, one master app to control the robot(from the handheld phone) which will control the slave app and receive the stream, and the second slave app which will run on the robot-strapped phone, controlling the motors/actuators/streaming to master app. I can not use third party apps unfortunately. I need to integrate the video stream code into my 2 apps.

什么选择有实现这一目标?也就是这很难做到,因为我从来没有与videostreaming,坚韧我做pretty的Java和Android开发好。我应该如何连接code /德$ C C流$,我怎么发起连接,将我需要使用UDP,而不是TCP / IP的工作?我真的不知道从哪里开始,有没有样品code的任何地方。我是pretty的肯定可以做到这一点。我无法找到任何东西让我在正确的方向开始了有益的。

What options are there for achieving this? Also is it very hard to do because I never worked with videostreaming, tough I am doing pretty good in both Java and Android development. How should I encode/decode the stream, how do I initiate the connection, will I need to work with UDP instead of TCP/IP ? I really don't know where to start, with no sample code anywhere. I am pretty sure this can be achieved. I just can't find anything useful to get me started in the right direction.

我偶然发现 spydroid ,但它使用VLC在桌面上,所以它没有良好的我的。

I stumbled across spydroid but it is using VLC on a desktop so its no good for me.

推荐答案

如果您不需要在应用程序中记录和回放功能,使用过的,现成的流媒体应用和球员是合理的选择。

If you do not need the recording and playback functionality in your app, using off-the-shelf streaming app and player is a reasonable choice.

如果你需要他们在你的应用程序,但是,您将不得不考虑 MediaRecorder API(服务器/摄像头的应用程序)和 MediaPlayer的(客户机/播放器应用程序)。

If you do need them to be in your app, however, you will have to look into MediaRecorder API (for the server/camera app) and MediaPlayer (for client/player app).

快速样品code服务器:

Quick sample code for the server:

// this is your network socket
ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(socket);
mCamera = getCameraInstance();
mMediaRecorder = new MediaRecorder();
mCamera.unlock();
mMediaRecorder.setCamera(mCamera);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
// this is the unofficially supported MPEG2TS format, suitable for streaming (Android 3.0+)
mMediaRecorder.setOutputFormat(8);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
mediaRecorder.setOutputFile(pfd.getFileDescriptor());
mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());
mMediaRecorder.prepare();
mMediaRecorder.start();

在球员方面,它是一个有点棘手,你可以试试这个:

On the player side it is a bit tricky, you could try this:

// this is your network socket, connected to the server
ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(socket);
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(pfd.getFileDescriptor());
mMediaPlayer.prepare();
mMediaPlayer.start();

不幸的是媒体播放器往往不喜欢这样,所以你有两个选择:要么(一)保存的数据从套接字文件和(后你有一个数据位)与媒体播放器的文件播放,或(b)使在本地运行,并能接受MediaPlayer的GET请求,使用HTTP头回复,和一个小的HTTP代理,那么从远程服务器,将它复制数据。对于(a)您将创建与媒体播放器的文件路径或文件的URL为(B)给它一个HTTP URL指向你的代理服务器。

Unfortunately mediaplayer tends to not like this, so you have a couple of options: either (a) save data from socket to file and (after you have a bit of data) play with mediaplayer from file, or (b) make a tiny http proxy that runs locally and can accept mediaplayer's GET request, reply with HTTP headers, and then copy data from the remote server to it. For (a) you would create the mediaplayer with a file path or file url, for (b) give it a http url pointing to your proxy.

另请参阅:

<一个href="http://stackoverflow.com/questions/6116880/stream-live-video-from-phone-to-phone-using-socket-fd/">Stream使用插座住在离手机视频,手机FD

<一个href="http://stackoverflow.com/questions/5343730/mediaplayer-stutters-at-start-of-mp3-playback/">MediaPlayer口吃的MP3开始播放

这篇关于直播流视频从一个android手机到另一个无线网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆