I am trying to record video from android camera2 sample
All works fine but when I play the video after recording (from the sd card), the video starts freezing and you can hear just the audio at the background and when the audio stops, the video start playing without the audio and the time of the video jumps from seconds to minites (03:24)
private void setUpMediaRecorder() throws IOException {
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setOutputFile(getVideoFile().getAbsolutePath());
mMediaRecorder.setVideoEncodingBitRate(10000000);
mMediaRecorder.setVideoFrameRate(30);
//mMediaRecorder.setMaxDuration(60000); // Set max duration 60 sec.
mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight());
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
int rotation = getWindowManager().getDefaultDisplay().getRotation();
int orientation = ORIENTATIONS.get(rotation);
if (mCameraType == 1) {
if (orientation == 90) {
mMediaRecorder.setOrientationHint(270);
} else if (orientation == 270) {
mMediaRecorder.setOrientationHint(90);
}
}
else {
mMediaRecorder.setOrientationHint(orientation);
}
mMediaRecorder.prepare();
}
Figure out that it works without those lines:
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
How can I make it works with sound?
The stupid solution is to restart the device. Is someone know why is that happening?
Thanks for helping