fix #189, #170, properly handle video recording on SD cards

This commit is contained in:
tibbi 2018-10-18 14:09:06 +02:00
parent 00884bb881
commit c6411b7b79
1 changed files with 9 additions and 1 deletions

View File

@ -766,12 +766,20 @@ class CameraPreview : ViewGroup, TextureView.SurfaceTextureListener, MyPreview {
try { try {
val videoSize = getCurrentResolution() val videoSize = getCurrentResolution()
mLastVideoPath = mActivity.getOutputMediaFile(false) mLastVideoPath = mActivity.getOutputMediaFile(false)
val uri = if (context.isPathOnSD(mLastVideoPath)) {
context.getDocumentFile(mLastVideoPath.getParentPath())?.createFile("video/mp4", mLastVideoPath.getFilenameFromPath())!!.uri
} else {
Uri.fromFile(File(mLastVideoPath))
}
val fileDescriptor = context.contentResolver.openFileDescriptor(uri, "w").fileDescriptor
val rotation = mActivity.windowManager.defaultDisplay.rotation val rotation = mActivity.windowManager.defaultDisplay.rotation
mMediaRecorder!!.apply { mMediaRecorder!!.apply {
setAudioSource(MediaRecorder.AudioSource.MIC) setAudioSource(MediaRecorder.AudioSource.MIC)
setVideoSource(MediaRecorder.VideoSource.SURFACE) setVideoSource(MediaRecorder.VideoSource.SURFACE)
setOutputFormat(MediaRecorder.OutputFormat.MPEG_4) setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
setOutputFile(mLastVideoPath) setOutputFile(fileDescriptor)
setVideoEncodingBitRate(10000000) setVideoEncodingBitRate(10000000)
setVideoFrameRate(30) setVideoFrameRate(30)
setVideoSize(videoSize.width, videoSize.height) setVideoSize(videoSize.width, videoSize.height)