通过WiFi连接从Android手机到另一个Android手机的视频流

时间:2014-10-17 09:52:05

标签: android sockets streaming

通过WiFi连接从Android手机到另一个Android手机的视频流,我正在使用

中引用的代码
http://stackoverflow.com/questions/14401340/live-stream-video-from-one-android-phone-to-another-over-wifi

这是服务器代码:

    // 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);
    mMediaRecorder.setOutputFile(pfd.getFileDescriptor());
    //mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());
    mMediaRecorder.prepare();
    mMediaRecorder.start();

这是客户端代码:

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

但是,如果我正在使用udp协议,那么是为双方创建套接字的代码吗?

(我在那里的评论中提出这个问题,因为我没有足够的声誉)

0 个答案:

没有答案