Search code examples
javaandroidandroid-studioandroid-mediaprojectionmediaprojectionmanager

Can't find screen recorded video (/sdcard/capture.mp4") - Mediaprojection API


I'm still a biginner on android APP development and I'm trying to use Mediaprojection API to record my screen .. the issue that I am facing now is.. After recording I cant find the video file in the defined location (sdcard/capture.mp4) .. below is the part of the code that show the location of where I want to save my video ...

private void initRecorder() {
    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
    mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
    mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    mMediaRecorder.setVideoEncodingBitRate(512 * 1000);
    mMediaRecorder.setVideoFrameRate(30);
    mMediaRecorder.setVideoSize(DISPLAY_WIDTH, DISPLAY_HEIGHT);
    mMediaRecorder.setOutputFile("/sdcard/capture.mp4");
}

Thank you very much for your support .


Solution

  • I solve the problem above by defining my path as shown on the line below ... I set the download folder as my destination and now I can see the recorded video NOTE: with this solution the new video will overwrite the previous one.

    Hope this will also help someone in future ..

    Thanks to nope4561759 for the contribution...

    mMediaRecorder.setOutputFile(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/video.mp4");