我正在尝试从android camera2 示例录制视频
一切正常,但是当我在录制后(从 sd 卡)播放视频时,视频开始冻结,您只能听到背景中的音频,当音频停止时,视频开始播放而没有音频和时间视频从秒跳到最小 (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();
}
弄清楚它在没有这些行的情况下也可以工作:
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
我怎样才能让它与声音一起工作?
愚蠢的解决方案是重新启动设备。有人知道为什么会这样吗?
感谢您的帮助