简体   繁体   English

两部Android手机之间的实时视频流

[英]Live Video Stream between two Android Phones

I am currently working on video streaming between two Android Phone. 我目前正在研究两个Android Phone之间的视频流。 I wrote an application which is able to record the video to the sd file (Using MediaRecorder); 我编写了一个能够将视频录制到sd文件中的应用程序(使用MediaRecorder); and I wrote another application which is able to display the video of the file. 然后我编写了另一个应用程序,该应用程序可以显示文件的视频。 Both applications work perfectly. 两种应用程序都能完美运行。

I found a website about "Broadcasting video with Android - without writing to local files" in following website. 我在以下网站中找到了一个有关“使用Android广播视频-无需写入本地文件”的网站。 It is exactly what I wanted to do. 这正是我想要做的。

http://www.mattakis.com/blog/kisg/20090708/broadcasting-video-with-android-without-writing-to-the-file-system http://www.mattakis.com/blog/kisg/20090708/broadcasting-video-with-android-without-writing-to-the-file-system

I modified my code. 我修改了我的代码。

For the video recorder, it is: 对于录像机,它是:

socket=severSocket.accept();
ParcelFileDescriptor=pfd;
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
recorder.setVideoFrameRate(15);
recorder.setVideoSize(320, 240);
recorder.setPreviewDisplay(holder.getSurface());
pfd = ParcelFileDescriptor.fromSocket(socket);
recorder.setOutputFile(pfd.getFileDescriptor());
recorder.prepare(); 
recorder.start();

For Video Player: 对于视频播放器:

Socket socket = new Socket(IP,PORT);
mMediaPlayer = new MediaPlayer();
pfd = ParcelFileDescriptor.fromSocket(socket);
mMediaPlayer.setDataSource(pfd.getFileDescriptor()); // <-- here is the problem
mMediaPlayer.setDisplay(holder); 
mMediaPlayer.prepare();
mMediaPlayer.setOnBufferingUpdateListener(this);            
mMediaPlayer.setOnCompletionListener(this);            
mMediaPlayer.setOnPreparedListener(this);            
mMediaPlayer.setOnVideoSizeChangedListener(this);
mMediaPlayer.start();

Program crush on mMediaPlayer.setDataSource(pfd.getFileDescriptor()); mMediaPlayer.setDataSource(pfd.getFileDescriptor());程序迷恋mMediaPlayer.setDataSource(pfd.getFileDescriptor()); on MediaPlayer I know I didnt setup the DataSource correctly. 在MediaPlayer上,我知道我没有正确设置数据源。 There must be additional setups for ParcelFileDescriptor to put into MediaPlayer. 要将ParcelFileDescriptor放入MediaPlayer,必须有其他设置。

Does anyone know how to use ParcelFileDescriptor for MediaPlayer? 有谁知道如何为媒体播放器使用ParcelFileDescriptor Any helpful advise or tips would be nice...... 任何有帮助的建议或技巧都将很好......

Thank You 谢谢

Will

in the video playing side you must create a welcome socket 在视频播放端,您必须创建一个欢迎套接字

ServerSocket welcomeSocket = new ServerSocket(portNumber);
socket soc = welcomeSocket.accept();

and use 和使用

mMediaplayer.prepareAsync();

instead of 代替

mMediaplayer.prepare();

Android does not natively support video streaming in Android 2.1 or below. Android本身不支持Android 2.1或更低版本中的视频流。 What we did was to get the images frame by frame; 我们要做的是逐帧获取图像。 and break each flame into BYTE[] and send over using Socket class. 然后将每个火焰分解为BYTE []并使用Socket类进行发送。 And in receiver's side, we rebuild the images using BYTE[] data received. 在接收方,我们使用接收到的BYTE[]数据重建图像。

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

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