在使用媒体播放器录制视频时,某些设备启动失败-19

时间:2014-03-08 10:39:21

标签: android android-videoview recording android-mediarecorder

我正在尝试使用带有摄像机配置文件480P的媒体记录器录制480X640视频,但在某些设备中,当我按下开始录制时,它会让我开始失败-19。

private void initRecorder() {

  if(recorder!=null) return;

    // to delete the previous mp4 file created
       File deletefile=new File(outputFileName!=null?outputFileName:"abc.mp4");
       if(deletefile.exists())
           deletefile.delete();

    //Create Folder
    File folder = new File(Environment.getExternalStorageDirectory()+"/Chance");
    if(!folder.exists() )
    {
    folder.mkdirs();
    }

    File outFile= new File(folder.toString(),System.currentTimeMillis()+".mp4"); 
    outputFileName= outFile.toString();
    System.out.println("Filename "+outputFileName); 
            if(outFile.exists())
                    outFile.delete();



            try{
                    //camera.stopPreview();
                    camera.unlock();
                    recorder=new MediaRecorder();
                    recorder.setCamera(camera);                      
                    recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
                    recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
                if(typ==1)                     
                {  
                    //sequence should not be change
                    //Setting the quality of front camera

                     recorder.setProfile(CamcorderProfile.get(1,CamcorderProfile.QUALITY_480P));

                     CameraInfo cameraInfo = new CameraInfo();
                     Camera.getCameraInfo(CameraInfo.CAMERA_FACING_FRONT, cameraInfo);
                     //To rotate the camera by 630 i.e 90 by default + 270=630
                     int rot=270;
                     recorder.setOrientationHint(rot);

                }else     //video settings for back camera
                {
                    recorder.setProfile(CamcorderProfile.get(0,CamcorderProfile.QUALITY_480P));

                    recorder.setOrientationHint(camera_orientation);
                }
                    recorder.setMaxDuration(20000);     //20 sec                 
                    recorder.setPreviewDisplay(holder.getSurface());

                    recorder.setOutputFile(outputFileName);
                    recorder.prepare();
                    Log.v(TAG,"MediaRecorder initilized"); 


            }
            catch(Exception e)
            {
            runOnUiThread(new Runnable(){


                    @Override
                    public void run(){
                    Toast.makeText(getApplicationContext(), "Unable to connect  camera", Toast.LENGTH_SHORT).show();
                    }
                 });

                    Log.v(TAG,"MediaRecorder failed to initilized");
                    e.printStackTrace();
            }

       //     beginRecording();


    }

修改

    private void initRecorder() {
            if(recorder!=null) return;

           // to delete the previous mp4 file created
            File deletefile=new File(outputFileName!=null?outputFileName:"abc.mp4");
            if(deletefile.exists())
            deletefile.delete();

          //Create Folder
    File folder = new File(Environment.getExternalStorageDirectory()+"/Chance");
    if(!folder.exists() )
    {
    folder.mkdirs();
    }

    File outFile= new File(folder.toString(),System.currentTimeMillis()+".mp4"); 
    outputFileName= outFile.toString();
    System.out.println("Filename "+outputFileName); 
            if(outFile.exists())
                    outFile.delete();



            try{

                    //camera.stopPreview();
                    camera.unlock();
                    recorder=new MediaRecorder();
                    recorder.setCamera(camera);                      
                    recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
                    recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
                if(typ==1)                     
                {  
                    //sequence should not be change
                 //Setting the quality of front camera
                 if(CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_480P))
                     recorder.setProfile(CamcorderProfile.get(1,CamcorderProfile.QUALITY_480P));
                 else if(CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_LOW))
                 {
                    Log.v(TAG,"MediaRecorder LOW QUALITY"); 
                     recorder.setProfile(CamcorderProfile.get(1,CamcorderProfile.QUALITY_LOW));

                     if(optimalVideoSize!=null)
                       recorder.setVideoSize(optimalVideoSize.width, optimalVideoSize.height);
                     else
                        recorder.setVideoSize(640, 480);     
                 }

                     CameraInfo cameraInfo = new CameraInfo();
                     Camera.getCameraInfo(CameraInfo.CAMERA_FACING_FRONT, cameraInfo);
                     //To rotate the camera by 630 i.e 90 by default + 270=630
                     int rot=270;
                     recorder.setOrientationHint(rot);


                }else     //video settings for back camera
                {
                    //Setting the quality of front camera
                     if(CamcorderProfile.hasProfile(0, CamcorderProfile.QUALITY_480P))
                        recorder.setProfile(CamcorderProfile.get(0,CamcorderProfile.QUALITY_480P));
                     else if(CamcorderProfile.hasProfile(0, CamcorderProfile.QUALITY_HIGH))
                     {
                        Log.v(TAG,"MediaRecorder HIGH QUALITY"); 
                         recorder.setProfile(CamcorderProfile.get(0,CamcorderProfile.QUALITY_HIGH));
                        if(optimalVideoSize!=null)
                            recorder.setVideoSize(optimalVideoSize.width, optimalVideoSize.height);
                        else
                            recorder.setVideoSize(640, 480);
                     }  
                     else
                     {
                        Log.v(TAG,"MediaRecorder LOW QUALITY"); 
                        recorder.setProfile(CamcorderProfile.get(0,CamcorderProfile.QUALITY_LOW));
                        if(optimalVideoSize!=null)
                            recorder.setVideoSize(optimalVideoSize.width, optimalVideoSize.height);
                        else
                            recorder.setVideoSize(640, 480); 
                     }


                    recorder.setOrientationHint(camera_orientation);
                }
                    recorder.setMaxDuration(20000);     //20 sec                 
                    recorder.setPreviewDisplay(holder.getSurface());

                    recorder.setOutputFile(outputFileName);
                    recorder.prepare();
                    Log.v(TAG,"MediaRecorder initilized"); 


            }
            catch(Exception e)
            {
            runOnUiThread(new Runnable(){


                    @Override
                    public void run(){
                    Toast.makeText(getApplicationContext(), "Unable to connect  camera", Toast.LENGTH_SHORT).show();
                    }
                 });

                    Log.v(TAG,"MediaRecorder failed to initilized");
                    e.printStackTrace();
            }

       //     beginRecording();


    }

1 个答案:

答案 0 :(得分:2)

  

相机不支持480P那么我应该怎么做才能录制480 X 640

如果相机不支持480p进行视频录制,则无法以480p录制。记录其他一些 支持的分辨率。 QUALITY_LOWQUALITY_HIGH是唯一可以保证得到支持的人。如果您不喜欢QUALITY_LOW结果,并且QUALITY_480P不可用,请记录QUALITY_HIGH