其他分享
首页 > 其他分享> > android-MediaRecorder在新的Google Glass固件(XE19.1)媒体服务器上无法正常工作,死于错误100

android-MediaRecorder在新的Google Glass固件(XE19.1)媒体服务器上无法正常工作,死于错误100

作者:互联网

我为Google Glass制作了一个视频录制应用程序.在Google发布固件XE19.1之前,该应用程序运行良好.我还有另一个固件为XE18.11的Google Glass.该应用程序仍可在带有XE18.11的Google Glass上运行.

我收到以下错误:

07-30 15:39:32.273: V/MediaRecorder(17101): video.h264enc.profile is set to : 1
07-30 15:39:32.679: W/IMediaDeathNotifier(17101): media server died
07-30 15:39:32.679: W/CameraBase(17101): Camera service died!
07-30 15:39:32.679: W/CameraBase(17101): mediaserver's remote binder Camera object died
07-30 15:39:32.687: E/CameraManager(17101): Media Recorder error: what=100, extra=0
07-30 15:39:32.726: E/Camera(17101): Error 100

我试过但没有用的东西:

>尝试MediaRecorder example from Google.仅适用于较旧的固件
>恢复出厂设置的谷歌眼镜
>尝试是否在录制前开始预览.都可以在较旧的固件上运行
>将SurfaceView更改为TextureView.都可以在较旧的固件上运行
>看了changelog GDK XE19.1
>搜索错误

这很奇怪,因为即使Google示例也不起作用.这是将SurfaceView更改为TextureView之后的代码:

public class CameraManager implements one rrorListener
{
    private final static String TAG = CameraManager.class.getName();
    private final static int PREVIEW_SIZE_WIDTH = 640;
    private final static int PREVIEW_SIZE_HEIGHT = 360;

    private Activity mContext;
    private Camera mCamera;
    private TextureView mCameraPreview;
    private CameraListener mCameraListener;
    private MediaRecorder mMediaRecorder;
    private File mOutputVideoFile;
    private boolean mRecording;
    private boolean mTakingPicture;

    public CameraManager(Activity context, TextureView cameraPreview,
            CameraListener cameraListener)
    {
        mRecording = false;
        mTakingPicture = false;
        mContext = context;

        mCameraPreview = cameraPreview;
        mCameraListener = cameraListener;
    }

    public void startRecording(File outputVideoFile)
    {
        Log.d(TAG, "startRecording");

        mOutputVideoFile = outputVideoFile;
        new MediaPrepareTask().execute(null, null, null);
    }

    public void stopRecording()
    {
        Log.d(TAG, "stopRecording");

        mRecording = false;

        // stop the recording
        mMediaRecorder.stop();
        // if we are using MediaRecorder, release it first
        releaseMediaRecorder();
        // take camera access back from MediaRecorder
        mCamera.lock();
        // release the camera immediately on pause event
        releaseCamera();
    }

    public boolean isBusyRecording()
    {
        return mRecording;
    }

    public void takePicture(final TakePictureCallback pictureCallback)
    {
        if (isBusyRecording() && !mTakingPicture)
        {
            mTakingPicture = true;

            mCamera.takePicture(null, null, new PictureCallback()
            {
                @Override
                public void onPictureTaken(final byte[] pictureData, Camera camera)
                {
                    pictureCallback.onPictureTaken(pictureData);
                    mTakingPicture = false;
                }
            });
        }
    }

    @TargetApi(Build.VERSION_CODES.KITKAT)
    private boolean prepareVideoRecorder()
    {
        Log.d(TAG, "prepareVideoRecorder");

        // BEGIN_INCLUDE (configure_preview)
        mCamera = CameraHelper.getDefaultCameraInstance();

        // 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 = mCamera.getParameters();
        List<Camera.Size> mSupportedPreviewSizes = parameters.getSupportedPreviewSizes();
        Camera.Size optimalSize = CameraHelper.getOptimalPreviewSize(mSupportedPreviewSizes,
                PREVIEW_SIZE_WIDTH, PREVIEW_SIZE_HEIGHT);

        // Use the same size for recording profile.
        CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
        profile.videoFrameWidth = optimalSize.width;
        profile.videoFrameHeight = optimalSize.height;

        // likewise for the camera object itself.
        parameters.setPreviewSize(profile.videoFrameWidth, profile.videoFrameHeight);
        mCamera.setParameters(parameters);
        try
        {
            // Requires API level 11+, For backward compatibility use {@link
            // setPreviewDisplay}
            // with {@link SurfaceView}
            mCamera.setPreviewTexture(mCameraPreview.getSurfaceTexture());
        }
        catch (IOException e)
        {
            Log.e(TAG, "Surface texture is unavailable or unsuitable" + e.getMessage());
            return false;
        }
        // END_INCLUDE (configure_preview)

        // BEGIN_INCLUDE (configure_media_recorder)
        mMediaRecorder = new MediaRecorder();
        mMediaRecorder.setOnErrorListener(this);

        // Step 1: Unlock and set camera to MediaRecorder
        mCamera.unlock();
        mMediaRecorder.setCamera(mCamera);

        // Step 2: Set sources
        mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
        mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

        // Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
        mMediaRecorder.setProfile(profile);

        // Step 4: Set output file
        mMediaRecorder.setOutputFile(mOutputVideoFile.toString());
        // END_INCLUDE (configure_media_recorder)

        // Step 5: Prepare configured MediaRecorder
        try
        {
            mMediaRecorder.prepare();
        }
        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;
        }
        return true;
    }

    private void releaseMediaRecorder()
    {
        Log.d(TAG, "releaseMediaRecorder");

        if (mMediaRecorder != null)
        {
            // clear recorder configuration
            mMediaRecorder.reset();
            // release the recorder object
            mMediaRecorder.release();
            mMediaRecorder = null;
            // Lock camera for later use i.e taking it back from MediaRecorder.
            // MediaRecorder doesn't need it anymore and we will release it if
            // the activity pauses.
            mCamera.lock();
        }
    }

    private void releaseCamera()
    {
        Log.d(TAG, "releaseCamera");

        if (mCamera != null)
        {
            // release the camera for other applications
            mCamera.release();
            mCamera = null;
        }
    }

    /**
     * Asynchronous task for preparing the {@link android.media.MediaRecorder}
     * since it's a long blocking operation.
     */
    class MediaPrepareTask extends AsyncTask<Void, Void, Boolean>
    {
        @Override
        protected Boolean doInBackground(Void... voids)
        {
            Log.d(TAG, "MediaPrepareTask - doInBackground");

            // initialize video camera
            if (prepareVideoRecorder())
            {
                // Camera is available and unlocked, MediaRecorder is prepared,
                // now you can start recording
                mMediaRecorder.start();

                mRecording = true;
            }
            else
            {
                // prepare didn't work, release the camera
                releaseMediaRecorder();
                return false;
            }
            return true;
        }

        @Override
        protected void onPostExecute(Boolean result)
        {
            if (!result)
            {
                mContext.finish();
            }

            mCameraListener.onCameraRecording();
        }
    }

    @Override
    public void one rror(MediaRecorder mr, int what, int extra)
    {
        Log.e(TAG, String.format("Media Recorder error: what=%d, extra=%d", what, extra));
    }
}

谢谢

解决方法:

不幸的是,这是我们的issue tracker中当前存在的已知问题.

更新:20.1更新已解决此问题.

标签:video-capture,google-gdk,android,google-glass
来源: https://codeday.me/bug/20191029/1958888.html