我想同时录制屏幕和从前置摄像头录制视频。可能吗?

时间:2019-11-05 07:50:41

标签: android mediarecorder

我想同时录制屏幕和从前置摄像头录制视频。可能吗。我尝试过它给媒体发布例外。只有两个作品之一

public void setupRecorder(int resultCode, Intent data)  {


    NativeAppRecordingService.dataIntentScreenCapture = data;
    NativeAppRecordingService.resultCodeDataScreenCapture = resultCode;

    NativeAppRecordingService.recorder.reset();
    recordingInfo = getRecordingInfo();
    NativeAppRecordingService.recorder.setVideoSource(SURFACE);

    // Enable Audio recording.......

    NativeAppRecordingService.recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    NativeAppRecordingService.recorder.setOutputFormat(MPEG_4);
    NativeAppRecordingService.recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
    NativeAppRecordingService.recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
    NativeAppRecordingService.recorder.setVideoSize(recordingInfo.width, recordingInfo.height);
    NativeAppRecordingService.recorder.setVideoEncodingBitRate(15 * 1000 * 100);/**change this for video quality */
    NativeAppRecordingService.recorder.setVideoFrameRate(recordingInfo.frameRate);
    //String outputVideoFileName = fileFormat.format(new Date());

    NativeAppRecordingService.recorder.setOutputFile(Utils.getOutputVideoFileNameForAmazonS3Bucket(""));

    // NativeAppRecordingService.recorder.setOutputFile(NativeAppRecordingService.video_file.getAbsolutePath());

    try {
        NativeAppRecordingService.recorder.prepare();

        NativeAppRecordingService.projection = NativeAppRecordingService.manager.getMediaProjection(resultCode, data);
        Surface surface = NativeAppRecordingService.recorder.getSurface();
        if (surface == null) {

            Toast.makeText(StartRecorderActivity.this, "Your device is not able to capture screen!", Toast.LENGTH_SHORT).show();
            File f = new File(Utils.getOutputVideoFileNameForAmazonS3Bucket(""));
            if (f.exists()) {
                f.delete();
            }

            // TODO if decive is not able to capture audio and video
            // todo cancel the test
            TerminatingTest();

        } else {

            NativeAppRecordingService.display = NativeAppRecordingService.projection.createVirtualDisplay(NativeAppRecordingService.DISPLAY_NAME,
                    recordingInfo.width, recordingInfo.height,
                    recordingInfo.density, VIRTUAL_DISPLAY_FLAG_PRESENTATION,
                    surface, null, null);

            NativeAppRecordingService.recorder.start();

            // todo PauseRecording
            NativeAppRecordingService.isRecording = true;

            finish();
        }


    } catch (IllegalStateException e) {

        e.printStackTrace();

        Toast.makeText(StartRecorderActivity.this, "Your device is not able to capture screen!", Toast.LENGTH_SHORT).show();
        File f = new File(Utils.getOutputVideoFileNameForAmazonS3Bucket(""));
        if (f.exists()) {
            f.delete();
        }

        // TODO if decive is not able to capture audio and video
        // todo cancel the test
        TerminatingTest();
    } catch (IOException e) {

        Toast.makeText(StartRecorderActivity.this, "Your device is not able to capture screen!", Toast.LENGTH_SHORT).show();
        File f = new File(Utils.getOutputVideoFileNameForAmazonS3Bucket(""));
        if (f.exists()) {
            f.delete();
        }

        // TODO if decive is not able to capture audio and video
        // todo cancel the test
        TerminatingTest();

    }
}

上面是屏幕录制,下面是视频录制

public static void setUpVideoRecorder() {
try {
    mMediaRecorder = new MediaRecorder();
    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
    mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
      mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
    /**
     * create video output file
     */
    video_file = getOutputMediaFile();
    /**
     * set output file in media recorder
     */
    mMediaRecorder.setOutputFile(video_file.getAbsolutePath());
    mMediaRecorder.setMaxDuration(300000);
    CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_480P);
    mMediaRecorder.setVideoFrameRate(profile.videoFrameRate);
    mMediaRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
    mMediaRecorder.setVideoEncodingBitRate(profile.videoBitRate);
    mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);

    mMediaRecorder.setAudioEncodingBitRate(profile.audioBitRate);
    mMediaRecorder.setAudioSamplingRate(profile.audioSampleRate);

   /* int rotation = windowManager.getDefaultDisplay().getRotation();
    switch (mSensorOrientation) {
        case SENSOR_ORIENTATION_DEFAULT_DEGREES:
            mMediaRecorder.setOrientationHint(DEFAULT_ORIENTATIONS.get(rotation));
            break;
        case SENSOR_ORIENTATION_INVERSE_DEGREES:
            mMediaRecorder.setOrientationHint(INVERSE_ORIENTATIONS.get(rotation));
            break;
    }*/
    mMediaRecorder.prepare();
}
catch (IOException ioe)
{
    Log.e(TAG,"setUpVideoRecorder ioe "+ioe);
}
}

这是LogCat

2019-11-05 14:46:52.581 11771-11771/com.seattleapplab.trymyui.beta E/MediaRecorder: start failed: -38
2019-11-05 14:46:52.581 11771-11771/com.seattleapplab.trymyui.beta W/System.err: java.lang.IllegalStateException
2019-11-05 14:46:52.581 11771-11771/com.seattleapplab.trymyui.beta W/System.err:     at android.media.MediaRecorder.start(Native Method)
2019-11-05 14:46:52.581 11771-11771/com.seattleapplab.trymyui.beta W/System.err:     at com.seattleapplab.trymyui.Activity.StartRecorderActivity.setupRecorder(StartRecorderActivity.java:229)
2019-11-05 14:46:52.582 11771-11771/com.seattleapplab.trymyui.beta W/System.err:     at com.seattleapplab.trymyui.Activity.StartRecorderActivity.onActivityResult(StartRecorderActivity.java:757)
2019-11-05 14:46:52.582 11771-11771/com.seattleapplab.trymyui.beta W/System.err:     at android.app.Activity.dispatchActivityResult(Activity.java:7454)
2019-11-05 14:46:52.582 11771-11771/com.seattleapplab.trymyui.beta W/System.err:     at android.app.ActivityThread.deliverResults(ActivityThread.java:4354)
2019-11-05 14:46:52.582 11771-11771/com.seattleapplab.trymyui.beta W/System.err:     at android.app.ActivityThread.handleSendResult(ActivityThread.java:4403)
2019-11-05 14:46:52.582 11771-11771/com.seattleapplab.trymyui.beta W/System.err:     at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
2019-11-05 14:46:52.582 11771-11771/com.seattleapplab.trymyui.beta W/System.err:     at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
2019-11-05 14:46:52.582 11771-11771/com.seattleapplab.trymyui.beta W/System.err:     at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
2019-11-05 14:46:52.582 11771-11771/com.seattleapplab.trymyui.beta W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1809)
2019-11-05 14:46:52.582 11771-11771/com.seattleapplab.trymyui.beta W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:106)
2019-11-05 14:46:52.582 11771-11771/com.seattleapplab.trymyui.beta W/System.err:     at android.os.Looper.loop(Looper.java:193)
2019-11-05 14:46:52.582 11771-11771/com.seattleapplab.trymyui.beta W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6692)
2019-11-05 14:46:52.582 11771-11771/com.seattleapplab.trymyui.beta W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
2019-11-05 14:46:52.582 11771-11771/com.seattleapplab.trymyui.beta W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
2019-11-05 14:46:52.582 11771-11771/com.seattleapplab.trymyui.beta W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

0 个答案:

没有答案