首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >android中正在运行另一个录屏应用程序时,无法录制视频

android中正在运行另一个录屏应用程序时,无法录制视频
EN

Stack Overflow用户
提问于 2017-12-30 14:53:17
回答 1查看 1.1K关注 0票数 1

我正在使用MediaRecorder录制视频。当第三方屏幕录像机正在运行时,媒体录像机通过非法状态异常。如果我关闭屏幕记录器应用程序,一切都会正常工作。有没有一个优雅的解决方案可以让我的应用程序访问MediaRecorder,即使另一个应用程序已经在使用它?

EN

Stack Overflow用户

回答已采纳

发布于 2018-01-02 14:41:22

一次只有一个应用程序可以访问麦克风。当屏幕记录器应用程序正在运行并可以访问麦克风时,我尝试使用内置本机摄像头录制视频,但由于麦克风忙于另一个应用程序而无法录制视频。

此外,没有标准的方式来通知另一个应用程序您想要访问麦克风(以便他们释放资源并允许您访问).I建议您简单地通知用户麦克风当前不可用,因为您无法做其他任何事情,或者我们可以在没有音频的情况下录制视频。

使用下面的代码,我已经录制了没有音频的视频。

代码语言:javascript
运行
复制
private boolean prepareVideoRecorder() {
    mCamera = Camera.open(findBackFacingCamera());
    mediaRecorder = new MediaRecorder();
    // store the quality profile required
    windowwidth = getWindowManager().getDefaultDisplay().getWidth();
    CamcorderProfile profile;
    if (windowwidth > 2000) {
        profile= CamcorderProfile.get(camid, CamcorderProfile.QUALITY_HIGH);
    } else {
        profile= CamcorderProfile.get(camid, CamcorderProfile.QUALITY_480P);
    }
    // Step 1: Unlock and set camera to MediaRecorder
    mCamera.unlock();
    mediaRecorder.setCamera(mCamera);

    // Step 2: Set sources value i.e. CAMERA,SURFACE, or DEFAULT
    mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    // Step 3: Set all other values contained in profile except audio settings
    mediaRecorder.setOutputFormat(profile.fileFormat);
    mediaRecorder.setVideoEncoder(profile.videoCodec);
    mediaRecorder.setVideoEncodingBitRate(profile.videoBitRate);
    mediaRecorder.setVideoFrameRate(profile.videoFrameRate);
    mediaRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);

    // Step 4: Seting output file
   // mediaRecorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO).toString());
    File videoStorageDir = Const.getFileDirectory(MainActivity.this);
    mediaRecorder.setOutputFile(videoStorageDir.getPath()+ File.separator + "/videofile.mp4");

    // Step 5: Set the preview output
    mediaRecorder.setPreviewDisplay(mvPreview.getHolder().getSurface());

    mediaRecorder.setMaxDuration(42000); // for 40 second (you can set video recording limit here)

    // Step 6: Prepare configured MediaRecorder
    try {
        mediaRecorder.prepare();
    } catch (IllegalStateException e) {
        releaseMediaRecorder();
        return false;
    } catch (IOException e) {
        releaseMediaRecorder();
        return false;
    }
    return true;
}
票数 3
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48031722

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档