两款Android手机之间的实时视频流 [英] Live Video Stream between two Android Phones

查看:575
本文介绍了两款Android手机之间的实时视频流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前工作视频之间的两个Android手机流媒体。 我写这是能够录制视频到SD文件的应用程序(使用MediaRecorder);我写了另外一个应用程序,它能够显示该文件的视频。这两个应用程序正常工作。

我发现了一个关于网站的广播视频与Android - 无需编写本地文件,在下面的网站。这正是我想做的事。

<一个href="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

我修改了code。

有关录像机, 它是:

 插座=的SeverSocket.accept();
ParcelFileDescriptor = PFD;
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEn codeR(MediaRecorder.AudioEn coder.AMR_NB);
recorder.setVideoEn codeR(MediaRecorder.VideoEn coder.MPEG_4_SP);
recorder.setVideoFrameRate(15);
recorder.setVideoSize(320,240);
recorder.set previewDisplay(holder.getSurface());
PFD = ParcelFileDescriptor.fromSocket(插座);
recorder.setOutputFile(pfd.getFileDescriptor());
。录音机prepare();
recorder.start();
 

有关视频播放器:

  Socket套接字=新的Socket(IP,端口);
mMediaPlayer =新的MediaPlayer();
PFD = ParcelFileDescriptor.fromSocket(插座);
mMediaPlayer.setDataSource(pfd.getFileDescriptor()); //&LT;  - 这里的问题
mMediaPlayer.setDisplay(保持器);
mMediaPlayer prepare()。
mMediaPlayer.setOnBufferingUpdateListener(本);
mMediaPlayer.setOnCompletionListener(本);
mMediaPlayer.setOn preparedListener(本);
mMediaPlayer.setOnVideoSizeChangedListener(本);
mMediaPlayer.start();
 

计划在暗恋的 mMediaPlayer.setDataSource(pfd.getFileDescriptor()); 上的MediaPlayer 我知道我正确didnt设置数据源。必须有额外的设置对于 ParcelFileDescriptor ,以投入的MediaPlayer。

有谁知道如何使用 ParcelFileDescriptor 作为MediaPlayer的? 任何有用的提醒或提示将是很好......

感谢您

威尔

解决方案

在视频播放端 你必须创建一个值得欢迎的插座

 的ServerSocket welcomeSocket =新的ServerSocket(端口号);
插座SOC = welcomeSocket.accept();
 

和使用

  mMediaplayer prepareAsync()。
 

而不是

  mMediaplayer prepare()。
 

I am currently working on video streaming between two Android Phone. I wrote an application which is able to record the video to the sd file (Using 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. 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

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()); on MediaPlayer I know I didnt setup the DataSource correctly. There must be additional setups for ParcelFileDescriptor to put into MediaPlayer.

Does anyone know how to use ParcelFileDescriptor for MediaPlayer? 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手机之间的实时视频流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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