-19
android
runtime_error
ai_generated
true
java.lang.RuntimeException: start failed. E/MediaRecorder: start failed: -19
ID: android/media-recorder-start-failed
85%Fix Rate
85%Confidence
1Evidence
2023-02-28First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| Android 12 (API 31) | active | — | — | — |
| Android 13 (API 33) | active | — | — | — |
Root Cause
MediaRecorder cannot start due to missing audio/video source permissions, invalid output file path, or unsupported encoder/format combination.
generic中文
MediaRecorder 由于缺少音频/视频源权限、输出文件路径无效或编码器/格式组合不受支持而无法启动。
Official Documentation
https://developer.android.com/reference/android/media/MediaRecorderWorkarounds
-
85% success Ensure all required permissions are granted: add <uses-permission android:name="android.permission.RECORD_AUDIO" /> and <uses-permission android:name="android.permission.CAMERA" /> in AndroidManifest.xml, and request them at runtime.
Ensure all required permissions are granted: add <uses-permission android:name="android.permission.RECORD_AUDIO" /> and <uses-permission android:name="android.permission.CAMERA" /> in AndroidManifest.xml, and request them at runtime.
-
90% success Use a valid output file path in the app's external cache directory. Example: File outputFile = new File(context.getExternalCacheDir(), "recording.mp4"); mediaRecorder.setOutputFile(outputFile.getAbsolutePath());
Use a valid output file path in the app's external cache directory. Example: File outputFile = new File(context.getExternalCacheDir(), "recording.mp4"); mediaRecorder.setOutputFile(outputFile.getAbsolutePath());
-
85% success Set the audio and video encoders to supported values. Example: mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
Set the audio and video encoders to supported values. Example: mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
中文步骤
确保已授予所有必要权限:在 AndroidManifest.xml 中添加 <uses-permission android:name="android.permission.RECORD_AUDIO" /> 和 <uses-permission android:name="android.permission.CAMERA" />,并在运行时请求。
使用应用程序外部缓存目录中的有效输出文件路径。示例:File outputFile = new File(context.getExternalCacheDir(), "recording.mp4"); mediaRecorder.setOutputFile(outputFile.getAbsolutePath());
将音频和视频编码器设置为支持的值。示例:mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
Dead Ends
Common approaches that don't work:
-
75% fail
Video recording with audio requires both CAMERA and RECORD_AUDIO permissions; missing audio permission causes start failure.
-
80% fail
MediaRecorder requires a writable file path; using a non-writable location leads to error -19.
-
70% fail
Not all devices support H.265; falling back to H.264 is safer but the error persists if not handled.