14

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

Sufian Latif
  • 13,086
  • 3
  • 33
  • 70
Will W
  • 151
  • 1
  • 1
  • 4
  • 1
    is that working for you? if it is working ,plz tell me how to solve this problem. – Aravi Dec 10 '13 at 08:19
  • i would love to know if you figured this out too. i have exactly the same problem and the answer below doesn't help – steveh Jul 05 '14 at 13:01

2 Answers2

4

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

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.

Milad Yarmohammadi
  • 1,253
  • 2
  • 22
  • 37
Will W
  • 151
  • 1
  • 1
  • 4