简体   繁体   English

如何在 Android 10 及更高版本中获取共享存储文件夹的文件路径?

[英]How to get file path of shared storage folder in Android 10 and above?

We are integrating scoped storage in our app, we are reading and writing video files in sahred storage eg Environment.DIRECTORY_MOVIES folder (shared storage movies directory) it is working as expected but we need to write custom metadata in video to do that we are using org.mp4parser:isoparser .我们正在我们的应用程序中集成范围存储,我们正在 sahred 存储中读取和写入视频文件,例如Environment.DIRECTORY_MOVIES文件夹(共享存储电影目录)它按预期工作,但我们需要在视频中写入自定义元数据来执行我们正在使用的操作org.mp4parser:isoparser To read and write metadata, this library needs file object before scoped storage we can get absolute path using Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES) now it's deprecated is there any other way to get the file path in scoped storage?为了读取和写入元数据,这个库在范围存储之前需要文件对象,我们可以使用 Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES) 获取绝对路径,现在它已被弃用有没有其他方法可以在范围存储中获取文件路径?

public static String readVideoMetadata(File videoFile) throws IOException {
    
        if (!videoFile.canRead()) {
            throw new IllegalStateException("No read permissions to file " + videoFile.getAbsolutePath());
        }
        if(!isImageFile(videoFile)) {
            try {
                IsoFile isoFile = new IsoFile(videoFile);
                if (null != Path.getPath(isoFile, "moov[0]/udta[0]/meta[0]/ilst/©cmt")) {
                    AppleCommentBox nam = Path.getPath(isoFile, "moov[0]/udta[0]/meta[0]/ilst/©cmt");
                    String xml = nam.getValue();
                    isoFile.close();
                    return xml;
                }
            } catch (OutOfMemoryError | Exception e) {
                e.printStackTrace();
            }
        }else{
            ExifInterface exifInterface=new ExifInterface(videoFile);
            String metaData= exifInterface.getAttribute(ExifInterface.TAG_USER_COMMENT);
            if(metaData!=null){
                return metaData;
            }
        }
    
        return "";
    }

Use FFMPEG Android library 使用 FFMPEG Android 库

You can get file path from media URI using the below code您可以使用以下代码从媒体 URI 获取文件路径

Uri safUri = intent.getData();
String inputVideoPath = FFmpegKitConfig.getSafParameterForRead(requireContext(), safUri);

You can read media information using this below function您可以使用以下功能阅读媒体信息

 MediaInformationSession mediaInformation = FFprobeKit.getMediaInformation("<file path or uri>");
mediaInformation.getMediaInformation();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取 Android 10 及更高版本的路径 /storage/emulated/0/Download/file_name.mime_type - How to get path /storage/emulated/0/Download/file_name.mime_type for Android 10 and above 如何获得安卓<shared-storage> Qt 的路径? - How to get the android <shared-storage> path from Qt? 如何使用 android 10 及更高版本中的 Scoped Storage 从保存在外部存储中的文件名中获取 URI? - How to get URI from filename which is saved in the external Storage using Scoped Storage in android 10 and above? 如何获取原始文件夹android中的文件路径 - how to get path of file in raw folder android 如何在android中获取资产文件夹的文件路径 - how to get file path of asset folder in android 如何在 Android Oreo (8.1) 或更高版本中从 URI 获取文件路径 - How to Get File Path from URI in Android Oreo (8.1) or above 如何从内部存储读取和写入来自 android 10 及更高版本的 txt 文件 - How to I read and write a txt file from android 10 and above from internal storage 如何在android 10及更高版本的android中获取捕获图像和图库图像的真实路径 - How to get real path of capture image and gallery image in android in android 10 and above 如何将图像保存在存储特定文件夹(图库)中并使用 java 从 android 11 以上或以下的存储中获取图像? - How do I save images in storage particular folder (gallery) & Get image from storage in above android 11 or below with java? 如何从android中的内部存储中获取文件的文件路径 - How to get file path of file from internal storage in android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM