MediaRecorder不会以代码开头

我正尝试将视频写入套接字(使用ParcelFileDescriptor)。 但是,在调用mediaPlayer.start()方法时 - 此消息发生IllegalStateException - “E / MediaRecorder:启动失败:-38”。

文件描述符的代码(Socket被程序调用时100%正确连接):

public ParcelFileDescriptor getFileDescriptorToSocket() {
        return ParcelFileDescriptor.fromSocket(socket);
    }

准备媒体记录器:

private boolean prepareMediaRecorder() {
        mediaRecorder = new MediaRecorder();
        camera.unlock();

        mediaRecorder.setCamera(camera);
        // mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
        mediaRecorder.setPreviewDisplay(cameraSurface.getHolder().getSurface());
        mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
        mediaRecorder.setVideoSize(320, 240);
        mediaRecorder.setVideoFrameRate(30);
        //mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_720P));
        mediaRecorder.setOutputFile(MainActivity.socketClient.getFileDescriptorToSocket().getFileDescriptor());

        try {
            mediaRecorder.prepare();
        } catch (IllegalStateException ise) {

            // TODO Delete test code
            Log.d(TAG, "Error during MediaRecorder preparing:  " + ise.getMessage());
            ise.printStackTrace();

            releaseMediaRecorder();
            return false;
        } catch (IOException ioe) {

            // TODO Delete test code
            Log.d(TAG, "Error during MediaRecorder preparing:  " + ioe.getMessage());
            ioe.printStackTrace();

            releaseMediaRecorder();
            return false;
        }

返回true; }

并要求开始录制:

private void startRecording() {
        if (!prepareMediaRecorder()) {

            // TODO Delete test code
            Log.d(TAG, "Error starting recording process");

            finish();
        } else {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        mediaRecorder.start();
                    } catch (Exception e) {
                        // TODO Delete test code
                        Log.d(TAG, "Error in recording thread:  " + e.getMessage());
                        e.printStackTrace();
                    }
                }
            }).start();

            recordingStatus = true;
        }
    }

我应该注意到,当我禁用开始记录方法 - 相机工作正常 - 我可以正常看到相机预览表面。

链接地址: http://www.djcxy.com/p/31143.html

上一篇: MediaRecorder do not start with code

下一篇: Android MediaRecorder produces corrupt video with green lines