In my app I use MediaMuxer to create a video file. Constructor of MediaMuxer requires absolute path of output file. Everything is ok with primary storage, but for secondary storage app doesn't work. As I check, in Lollipop user has to pick output directory in external storage, using new Intent ACTION_OPEN_DOCUMENT_TREE (How to use the new SD card access API presented for Android 5.0 (Lollipop)?) But on result of this Intent we get DocumentFile. I don't know how to create new video file with MediaMuxer and this DocumentFile. Can someone help me?
Asked
Active
Viewed 1,310 times
1 Answers
1
There is a method createFile(String mimeType, String displayName)
- just call it on the DocumentFile directory instance:
DocumentFile newFile = documentFileDir.createFile("application/octet-stream", fileName);
OutputStream os = getContentResolver().openOutputStream(newFile.getUri());
... // write your data

Quark
- 1,578
- 2
- 19
- 34
-
I might be missing something, but I don't think this answers the question. MediaMuxer only takes a String path or a FileDescriptor. Neither DocumentFile nor OutputStream are either of those things, so how can MediaMuxer be used with them? – kyp4 Jul 12 '22 at 16:52