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

发布于 2024-10-21 19:47:19 字数 1950 浏览 8 评论 0原文

我目前正在研究两部 Android 手机之间的视频流。 我编写了一个能够将视频录制到 sd 文件的应用程序(使用 MediaRecorder);我编写了另一个能够显示文件视频的应用程序。两个应用程序都可以完美运行。

我在以下网站中找到了一个关于“使用 Android 广播视频 - 无需写入本地文件”的网站。这正是我想做的。

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

我修改了我的代码。

对于录像机来说, 它是:

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

对于视频播放器:

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

在 MediaPlayer 上对 mMediaPlayer.setDataSource(pfd.getFileDescriptor()); 进行程序粉碎 我知道我没有正确设置数据源。必须对 ParcelFileDescriptor 进行额外设置才能放入 MediaPlayer。

有谁知道如何使用 MediaPlayer 的 ParcelFileDescriptor ? 任何有用的建议或提示都会很好......

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

℉絮湮 2024-10-28 19:47:19

在视频播放端
您必须创建一个欢迎套接字

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

并使用

mMediaplayer.prepareAsync();

而不是

mMediaplayer.prepare();

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();
波浪屿的海角声 2024-10-28 19:47:19

Android 本身不支持 Android 2.1 或更低版本的视频流。我们所做的就是逐帧获取图像;并将每个火焰分解为 BYTE[] 并使用 Socket 类发送。在接收方,我们使用接收到的 BYTE[] 数据重建图像。

Android does not natively support video streaming in Android 2.1 or below. What we did was to get the images frame by frame; and break each flame into BYTE[] and send over using Socket class. And in receiver's side, we rebuild the images using BYTE[] data received.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文