1

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 .

TKim
  • 13
  • 5
  • https://stackoverflow.com/questions/32789157/how-to-write-files-to-external-public-storage-in-android-so-that-they-are-visibl – CommonsWare Feb 26 '18 at 14:46

2 Answers2

1

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");
rjr-apps
  • 352
  • 4
  • 13
  • hello nope4561759 .. Thanks for your support .. I tried the method above but still I cant find the video ... there is no any error from the code also I tried to check the Logcat it shows no error .. but from the warning I could get this two line .... 02-27 10:10:45.337 28185-28185/com.confusedbox.screenrecorder W/System: ClassLoader referenced unknown path: /data/app/com.confusedbox.screenrecorder-2/lib/arm64 02-27 10:10:46.214 28185-28243/com.confusedbox.screenrecorder W/linker: /vendor/lib64/libhwuibp.so: unused DT entry: type 0xf arg 0xe3a – TKim Feb 27 '18 at 09:18
  • and from Info .. I could get these lines ....02-27 10:10:45.255 28185-28185/? I/art: Late-enabling -Xcheck:jni 02-27 10:10:45.256 28185-28185/? I/art: Reinit property: dalvik.vm.checkjni= false 02-27 10:10:46.023 28185-28185/com.confusedbox.screenrecorder I/HwCust: Constructor found for class android.app.HwCustActivityImpl 02-27 10:10:46.038 28185-28185/com.confusedbox.screenrecorder I/HwCust: Constructor found for class android.app.HwCustHwWallpaperManagerImpl – TKim Feb 27 '18 at 09:20
  • The program that I am using I downloaded from this link ..https://github.com/chinmoyp/screenrecorder Thank you very much for your support – TKim Feb 27 '18 at 09:23
  • Have you set the proper write permission in the manifest? See the [official documentation](https://developer.android.com/training/data-storage/files.html#WriteExternalStorage) on writing to external storage. – rjr-apps Feb 27 '18 at 17:59
0

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");
TKim
  • 13
  • 5