【发布时间】:2021-07-09 12:17:41
【问题描述】:
我们正在我们的应用程序中集成范围存储,我们正在 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 "";
}
【问题讨论】:
-
youtube.com/playlist?list=PLQkwcJG4YTCR9jZq8O19nUL2hLqmLYX4M 这是 youtube 上的一个很棒的视频教程,看看
-
感谢分享,我实现了保存、删除创建文件的代码,需要使用mp4parser在视频中编写自定义元数据。
标签: android scoped-storage mp4parser