[英]How to get path /storage/emulated/0/Download/file_name.mime_type for Android 10 and above
[英]How to get file path of shared storage folder in Android 10 and above?
我們正在我們的應用程序中集成范圍存儲,我們正在 sahred 存儲中讀取和寫入視頻文件,例如Environment.DIRECTORY_MOVIES
文件夾(共享存儲電影目錄)它按預期工作,但我們需要在視頻中寫入自定義元數據來執行我們正在使用的操作org.mp4parser:isoparser
。 為了讀取和寫入元數據,這個庫在范圍存儲之前需要文件對象,我們可以使用 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 "";
}
您可以使用以下代碼從媒體 URI 獲取文件路徑
Uri safUri = intent.getData();
String inputVideoPath = FFmpegKitConfig.getSafParameterForRead(requireContext(), safUri);
您可以使用以下功能閱讀媒體信息
MediaInformationSession mediaInformation = FFprobeKit.getMediaInformation("<file path or uri>");
mediaInformation.getMediaInformation();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.