相机媒体服务器死了

时间:2017-05-02 15:58:18

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

我有一个自定义视频录制应用程序已在多台设备上运行,但当我尝试在三星Galaxy Core Prime(SM-G361F)上运行时,相机会因以下错误消息而死机:

 W/IMediaDeathNotifier: media server died
 W/CameraBase: Camera service died!
 W/CameraBase: mediaserver's remote binder Camera object died
 W/AudioSystem: AudioPolicyService server died!
 W/AudioSystem: AudioFlinger server died!
 E/Camera: Error 100

这是相机的设置代码:

//@android.support.annotation.RequiresApi(api = Build.VERSION_CODES.M)
public boolean prepareVideoRecorderMP4( int rotation ){
    isImage = false;
    mLastRotation = rotation;
    setCamera( CameraHelper.getDefaultCameraInstance() );
    if( getCamera() == null )
    {
        return false;
    }
    // We need to make sure that our preview and recording video size are supported by the
    // camera. Query camera to find all the sizes and choose the optimal size given the
    // dimensions of our preview surface.
    Camera.Parameters parameters = getCamera().getParameters();
    int rotationCorrected = correctCameraRotation( rotation );
    parameters.setRotation( rotationCorrected );
    Camera.Size optimalSize = getCameraSize( parameters );
    parameters.setPreviewSize( optimalSize.width, optimalSize.height); 
    getCamera().setParameters(parameters);

    try {

        Surface sf = getHolder().getSurface();
        if( !sf.isValid())
        {
            restoreHolder();
            Surface sf2 = getHolder().getSurface();
        }
        setCameraDisplay();
    } catch (IOException e) {
        Log.e(TAG, "Surface texture is unavailable or unsuitable" + e.getMessage());
        return false;
    }

    mMediaRecorder = new MediaRecorder();
    try
    {

        unlockCamera();
        try {
            mMediaRecorder.setCamera(getCamera());
        }catch( Exception ex )
        {
            Log.e(TAG, "I don't know what happened... " + ex.getMessage());
        }
        // Step 2: Set sources
        mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT );
        mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

        CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_480P);
        // FIXME resolution
        profile.videoFrameWidth = optimalSize.width; //     HUAWEI  -> OK
        profile.videoFrameHeight = optimalSize.height; //   HUAWEI    -> OK
        profile.fileFormat = MediaRecorder.OutputFormat.MPEG_4;
        profile.videoCodec = MediaRecorder.VideoEncoder.H264;
        profile.audioCodec = MediaRecorder.AudioEncoder.AAC;
        String manufacturer = Build.MANUFACTURER;
        manufacturer = manufacturer.toUpperCase();
        if( !manufacturer.contains("HUAWEI") )
        {
            profile.videoFrameRate = 24; //                   HUAWEI  -> KO
        }
        profile.videoBitRate = 690000; //                   HUAWEI  -> OK//            // reduce audio quality
        profile.audioBitRate = 16000; //                    HUAWEI    -> OK
        profile.audioChannels = 1; //                       HUAWEI    -> OK

        // Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
        /*  This method should be called after the video AND audio sources
        are set, and before setOutputFile()  */
        mMediaRecorder.setProfile(profile);
        mMediaRecorder.setOrientationHint( rotationCorrected );
        // Step 4: Set output file
        mOutputFile = CameraHelper.getOutputMediaFile(CameraHelper.MEDIA_TYPE_VIDEO);
        if (mOutputFile == null) {
            return false;
        }
        mMediaRecorder.setOutputFile(mOutputFile.getPath());
        // END_INCLUDE (configure_media_recorder)
    }
    catch( IllegalStateException ex )
    {
        /*
            if setOutputFormat is called after prepare() or before
            setAudioSource()/setVideoSource()
        *//*
            if setVideoFrameRate is called after
            prepare() or before setOutputFormat().
        */
        Log.e(TAG, "Method called without necessary previous steps " + ex.getMessage());
    }
    catch( Exception ex )
    {
        Log.e(TAG, "I don't know what happened... " + ex.getMessage());
    }
    // Step 5: Prepare configured MediaRecorder
    try {
        mMediaRecorder.prepare();
        //mMediaRecorder.getSurface();
    } catch (IllegalStateException e) {
        Log.d(TAG, "IllegalStateException preparing MediaRecorder: " + e.getMessage());
        releaseMediaRecorder();
        return false;
    } catch (IOException e) {
        Log.d(TAG, "IOException preparing MediaRecorder: " + e.getMessage());
        releaseMediaRecorder();
        return false;
    }
    catch( Exception ex )
    {
        Log.e(TAG, "I don't know what happened... " + ex.getMessage());
        return false;
    }
    isPhotoReady = false;
    return true;
}

我错过了什么吗?

0 个答案:

没有答案