【问题标题】:Android Force Close issue of Video Recorder implementation in Custom Camera appAndroid Force Close 自定义相机应用中的 Video Recorder 实现问题
【发布时间】:2013-09-07 04:06:46
【问题描述】:

我正在开发一个 Android 自定义相机应用程序并尝试在其中实现录像机功能。我正在使用下面的代码

    private boolean prepareMediaRecorder()
    {
        myCamera = getCameraInstance();
        mediaRecorder = new MediaRecorder();
        myCamera.unlock();
        mediaRecorder.setCamera(myCamera);
        mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
        mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
        mediaRecorder.setPreviewDisplay(myCameraSurfaceView.getHolder().getSurface());
        try 
        {
            File newFile = File.createTempFile("videocapture", ".mp4", Environment.getExternalStorageDirectory());
            sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
            mediaRecorder.setOutputFile(newFile.getAbsolutePath());     
        } 
        catch (IOException e)
        {
            e.printStackTrace();
            finish();
        }
        try 
        {
            mediaRecorder.prepare();
        }
        catch (IllegalStateException e)
        {
            releaseMediaRecorder();
            return false;
        }
        catch (IOException e)
        {
            releaseMediaRecorder();
            return false;
        }
        return true;
    }

但如果我使用相同的代码并在 Galaxy 选项卡上运行它,我会在此代码位置强制关闭

             mediaRecorder.start();

错误日志是这样的。

http://textuploader.com/?p=6&id=ngcFk

当我更改代码时,代码也可以正常工作

   mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));

到

   mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_LOW));

不明白为什么会这样。请帮忙!谢谢!

【问题讨论】:

    标签: java android camera android-camera video-capture


    【解决方案1】:

    您应该检查配置文件是否存在。我认为不支持选项卡。你可以试试hasprofile

    【讨论】:

    • 你能解释一下如何准确地使用这个hasprofile代码吗?我试过了……但没有结果!
    • hasprofile 表示配置文件存在与否的天气。您可以检查返回值,例如 if(CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_LOW)){ mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_LOW));与 QUALITY_HIGH 相同
    • 希望你对 QUALITY_HIGH 进行了同样的尝试,所以代码看起来像 if(camcoderprofile.hasprofile(quality_high){ setprofile(quality_high); } else if(camcoderprofile.hasprofile(quality_low) { setprofile(quality_low) ; } 仅当相机支持时才会选择配置文件。
    • 是的。我也试过了...得到了这个错误.. java.lang.NoSuchMethodError: android.media.CamcorderProfile.hasProfile
    • 它是 API 级别 11 的一种方法。请检查 developer.android.com/reference/android/media/…, int)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-23
    • 2015-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多