Camera preview is black when using getExternalStorageDirectory to save video

I am shooting a video using camera2 API and Google code example .

I encounter a problem when I try to change the location of the output, which will be saved on sdcard/MyApp/filenameinstead Android/data/my_package/filename.

Here is a way:

private File getVideoFile(Context context) {
    // Not working, cause black preview
    return new File(Environment.getExternalStorageDirectory().getPath() +
                                                    "/myApp/", "myVideo.mp4");
    // Working
    return new File(context.getExternalFilesDir(null), "myVideo.mp4");
}

So my question is why saving video on the SD card causes a "Black Preview" and how can I save the video on the SD card?

Thanks!

CHANGE the resolution I set:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA"/>
+4
source share
2 answers

Finally, I found a solution.

, , , .

myApp, , .

, . :

private File getVideoFile(Context context) {
    File folder = new File (Environment.getExternalStorageDirectory().getPath() + "/myApp/");
    folder.mkdirs();
    return new File(Environment.getExternalStorageDirectory().getPath() + "/myApp/", "myVideo.mp4");
}
0

SD- ( ), API: getExternalFilesDirs().

API . - SD-. 2 SD-, , "sdcard" . , .

0

Source: https://habr.com/ru/post/1615222/


All Articles