存储访问框架中 MediaRecorder 中的 SetOutputFile [英] SetOutputFile in MediaRecorder in Storage Access Framework
问题描述
我想在 Android 上通过 MediaRecorder 使用存储访问框架 (SAF).但是在 SAF 方案下,您不应该依赖绝对路径,而应该依赖您之前获得权限的 Uri.
I want to use the Storage Access Framework (SAF) on Android with MediaRecorder. But under the SAF scheme, you should not rely on absolute path, but rather on Uri that you previously took permissions for.
什么是好的工作方式,如何使用 MediaRecorder 与 Android 的 SAF 新方法一致?比方说,作为(有据可查的)起点,您从这里开始:
What is the good way to work, how can one use MediaRecorder consistently with the new approach of Android's SAF? Let's say, as a (well documented) starting point you start from here:
List<UriPermission> permission= getContentResolver().getPersistedUriPermissions();
而且你想到达那里:
mMediaRecorder.setOutputFile(/*Some arguments*/);
mMediaRecorder.prepare();
中间步骤是什么?
推荐答案
欢迎您在 ContentResolver
上尝试 openFileDescriptor()
,以获得 FileDescriptor
在由 Uri
标识的内容上.然后,将其传递给采用 FileDescriptor
的 MediaRecorder
上的 setOutputFile()
版本.这将如何工作将在很大程度上取决于您正在录制的内容以及文档提供者是否支持搜索(这几乎可以归结为此 Uri
是否由常规文件支持).
You are welcome to try openFileDescriptor()
on ContentResolver
, to get a FileDescriptor
on the content identified by the Uri
. Then, pass that to the version of setOutputFile()
on MediaRecorder
that takes a FileDescriptor
. How well this will work will depend a lot on what you are recording and whether the documents provider supports seeking (which pretty much boils down to whether this Uri
is backed by a regular file).
这篇关于存储访问框架中 MediaRecorder 中的 SetOutputFile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!