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

678 Views Asked by At

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 .

2

There are 2 best solutions below

0
On BEST ANSWER

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");
4
On

The issue here is probably "/sdcard/". It is generally best practice to use Environment.getExternalStorageDirectory() instead of "/sdcard/", as not all Android devices use that as their external storage directory (I haven't seen that on any Android device for a while now, actually). On my Pixel running Android 8.1.0, Environment.getExternalStorageDirectory() returns an absolute path of "/storage/emulated/0".

So instead of:

mMediaRecorder.setOutputFile("/sdcard/capture.mp4");

Try this:

String dir = Environment.getExternalStorageDirectory().getAbsolutePath();
mMediaRecorder.setOutputFile(dir + "/capture.mp4");