I am trying to stream video over socket.
Here is the code snippet -
serverSocket = new ServerSocket(serverPort);
receiverSocket = new Socket();
receiverSocket.connect(new InetSocketAddress(serverIP, serverPort));
// receiverSocket.setReceiveBufferSize(500000);
receiverSocket.setSoTimeout(3000);
senderSocket = serverSocket.accept();
// senderSocket.setReceiveBufferSize(500000);
ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(senderSocket);
FileDescriptor fd = pfd.getFileDescriptor();
mMediaRecorder.setOutputFile(fd);
// mMediaRecorder.setOutputFile(filePath);
mMediaRecorder.setVideoEncodingBitRate(10000000);
mMediaRecorder.setVideoFrameRate(30);
mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight());
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mMediaRecorder.setOrientationHint(orientation);
mMediaRecorder.prepare();
However I get IllegalStateException on call to prepare().
java.lang.IllegalStateException
at android.media.MediaRecorder._prepare(Native Method)
at android.media.MediaRecorder.prepare(MediaRecorder.java:742)
at com.example.i047468.videostreaming.VideoRecordingAsyncTask.setUpMediaRecorder(VideoRecordingAsyncTask.java:90)
at com.example.i047468.videostreaming.VideoRecordingAsyncTask.doInBackground(VideoRecordingAsyncTask.java:52)
When I set the output file to "filePath" on sdcard all goes fine. So I guess it's not able to set the outputfile to socket fd and hence prepare fails.
How do I get this working? What is going wrong here? Exception stack is not revealing much.
Regards, Shailesh
Aucun commentaire:
Enregistrer un commentaire