录像时调用MediaRecorder的start()时发生start failed: -19错误

简介:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
     
private  void  start() {
         if  (isRecording)
         {
             // 停止录像并释放myFrontFacingCamera
             myVideoRecorder.stop();
             releaseVideoRecorder();
             /*myFrontFacingCamera.lock();*/ // 从Android4.0开始,这个方法由系统自动调用
             
             // TODO:通知用户录像已停止,设置停止按钮为不可用
             
             isRecording = false;
         } else {
             // 初始化myFrontFacingCamera
             if (prepareVideoRecorder()) {
                 // myFrontFacingCamera已可用并解锁,VideoRecorder已就绪
                 // 现在可以开始录像
                 /*myFrontFacingCamera.startPreview();*/
                 myVideoRecorder.start();
                 
                 // TODO:通知用户录像已开始,设置开始按钮为不可用
                 
                 isRecording = true;
             } else {
                 // 准备未能完成,释放myFrontFacingCamera
                 releaseVideoRecorder();
                 // TODO:通知用户
             }
         }
     }
 
private boolean prepareVideoRecorder()
     {
         /*myFrontFacingCamera = getFrontFacingCamera();*/ // 在onCreate()中已经创建了myFrontFacingCamera对象
         myVideoRecorder = new MediaRecorder();
         
         // 解锁并将摄像头指向myVideoRecorder
         /*myFrontFacingCamera.unlock();*/ //在Android4.0之后这个方法由系统自动调用
         myVideoRecorder.setCamera(myFrontFacingCamera);
         
         // TODO:指定源,如果声音源不行,就用麦克作为声音源
         myVideoRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
         myVideoRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
         
         // 指定CamcorderProfile(需要API Level 8以上版本),这里的Profile包括了输出格式,声音编码类型和视频编码类型
         myVideoRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_LOW));
         
         myVideoRecorder.setVideoSize(100, 100);
         
         // 指定输出文件
         myVideoRecorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO).toString());
         
         // 指定预览输出
         myVideoRecorder.setPreviewDisplay(myVideoPreview.getHolder().getSurface());
         
         // 根据以上配置准备myVideoRecorder
         try  {
             myVideoRecorder.prepare();
         catch  (IllegalStateException e) {
             Log.d( "VideoActivity:prepareVideoRecorder" "准备myVideoRecorder时发生IllegalStateException错误"  "\n"  + e.getMessage());
             releaseVideoRecorder();
             return  false ;
         catch  (IOException e) {
             Log.d( "VideoActivity:prepareVideoRecorder" "准备myVideoRecorder时发生IOException错误"  "\n"  + e.getMessage());
             releaseVideoRecorder();
             return  false ;
         }
         
         return  true ;
         
         
         
     }

解决方案:

  myVideoRecorder.setVideoSize(100, 100); 这句话注释掉就行了

相关文章
|
NoSQL API 语音技术
Freeswitch如何接收 RECORD_STOP 和 RECORD_START事件
Freeswitch如何接收 RECORD_STOP 和 RECORD_START事件
|
6月前
zabbix-agent问题提示interrupted system call
zabbix-agent问题提示interrupted system call
80 0
|
8月前
|
安全 Java API
为什么启动线程不直接调用run(),而要调用start(),如果调用两次start()方法会有什么后果
1位工作6年的小伙伴去某里P6一面,被问到这样一道面试题,说,为什么启动一个线程不直接调用run()方法,而要调用start()方法来启动,如果调用两次start()会有什么后果?
61 0
|
10月前
脚本文件stop和status与start类似,这里不再描述。
脚本文件stop和status与start类似,这里不再描述。
31 0
|
Python
pychram中提示:Process finished with exit code 0
"Process finished with exit code 0" 是PyCharm中的提示信息,表示程序已经成功地执行完毕并且没有发生任何错误。在PyCharm中,当程序正常终止并返回退出代码0时,这个消息会在控制台中显示。 在PyCharm中运行程序时,它会在一个单独的进程中执行,当程序完成执行后,它会向操作系统返回一个退出代码。退出代码0表示程序成功执行完毕,而非零的退出代码通常表示错误或异常终止。 当出现"Process finished with exit code 0"的提示时,意味着你的程序已经成功地执行完毕,没有发生任何错误或异常情况。你可以通过检查程序输出或任何其他预
1224 0
|
Shell
奥比中光ROS启动节点运行异常退出:[camera/driver-2] process has finished cleanly
奥比中光ROS启动节点运行异常退出:[camera/driver-2] process has finished cleanly
347 0
奥比中光ROS启动节点运行异常退出:[camera/driver-2] process has finished cleanly
飞思卡尔codewarrior下载出现USBD connection error:Failed to connect to targe(Reason :Target reset pin time out)
飞思卡尔codewarrior下载出现USBD connection error:Failed to connect to targe(Reason :Target reset pin time out)
飞思卡尔codewarrior下载出现USBD connection error:Failed to connect to targe(Reason :Target reset pin time out)
首次运行Flutter失败报错(Finished with error: Gradle task assembleDebug failed with exit code 1)
首次运行Flutter失败报错(Finished with error: Gradle task assembleDebug failed with exit code 1)
302 0
首次运行Flutter失败报错(Finished with error: Gradle task assembleDebug failed with exit code 1)
|
测试技术 API Android开发
【错误记录】Oboe / AAudio 播放器报错 ( onEventFromServer - AAUDIO_SERVICE_EVENT_DISCONNECTED - FIFO cleared )
【错误记录】Oboe / AAudio 播放器报错 ( onEventFromServer - AAUDIO_SERVICE_EVENT_DISCONNECTED - FIFO cleared )
277 0