changed media retriever failure handling
This commit is contained in:
parent
2fc15a126b
commit
fe12767b4a
4 changed files with 116 additions and 107 deletions
|
@ -199,6 +199,7 @@ public class MetadataHandler implements MethodChannel.MethodCallHandler {
|
|||
private Map<String, String> getVideoAllMetadataByMediaMetadataRetriever(String uri) {
|
||||
Map<String, String> dirMap = new HashMap<>();
|
||||
MediaMetadataRetriever retriever = StorageUtils.openMetadataRetriever(context, Uri.parse(uri));
|
||||
if (retriever != null) {
|
||||
try {
|
||||
for (Map.Entry<Integer, String> kv : VIDEO_MEDIA_METADATA_KEYS.entrySet()) {
|
||||
Integer key = kv.getKey();
|
||||
|
@ -221,6 +222,7 @@ public class MetadataHandler implements MethodChannel.MethodCallHandler {
|
|||
// cannot rely on `MediaMetadataRetriever` being `AutoCloseable` on older APIs
|
||||
retriever.release();
|
||||
}
|
||||
}
|
||||
return dirMap;
|
||||
}
|
||||
|
||||
|
@ -317,6 +319,7 @@ public class MetadataHandler implements MethodChannel.MethodCallHandler {
|
|||
private Map<String, Object> getVideoCatalogMetadataByMediaMetadataRetriever(String uri) {
|
||||
Map<String, Object> metadataMap = new HashMap<>();
|
||||
MediaMetadataRetriever retriever = StorageUtils.openMetadataRetriever(context, Uri.parse(uri));
|
||||
if (retriever != null) {
|
||||
try {
|
||||
String dateString = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DATE);
|
||||
String rotationString = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);
|
||||
|
@ -357,6 +360,7 @@ public class MetadataHandler implements MethodChannel.MethodCallHandler {
|
|||
// cannot rely on `MediaMetadataRetriever` being `AutoCloseable` on older APIs
|
||||
retriever.release();
|
||||
}
|
||||
}
|
||||
return metadataMap;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ class VideoThumbnailFetcher implements DataFetcher<InputStream> {
|
|||
@Override
|
||||
public void loadData(@NonNull Priority priority, @NonNull DataCallback<? super InputStream> callback) {
|
||||
MediaMetadataRetriever retriever = StorageUtils.openMetadataRetriever(model.getContext(), model.getUri());
|
||||
if (retriever != null) {
|
||||
try {
|
||||
byte[] picture = retriever.getEmbeddedPicture();
|
||||
if (picture != null) {
|
||||
|
@ -46,6 +47,7 @@ class VideoThumbnailFetcher implements DataFetcher<InputStream> {
|
|||
retriever.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup() {
|
||||
|
|
|
@ -135,6 +135,7 @@ public class SourceImageEntry {
|
|||
// finds: width, height, orientation/rotation, date, title, duration
|
||||
private void fillByMediaMetadataRetriever(@NonNull Context context) {
|
||||
MediaMetadataRetriever retriever = StorageUtils.openMetadataRetriever(context, uri);
|
||||
if (retriever != null) {
|
||||
try {
|
||||
String width = null, height = null, rotation = null, durationMillis = null;
|
||||
if (isImage()) {
|
||||
|
@ -180,6 +181,7 @@ public class SourceImageEntry {
|
|||
retriever.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// expects entry with: uri, mimeType
|
||||
// finds: width, height, orientation, date
|
||||
|
|
|
@ -460,7 +460,8 @@ public class StorageUtils {
|
|||
}
|
||||
retriever.setDataSource(context, uri);
|
||||
} catch (Exception e) {
|
||||
Log.e(LOG_TAG, "failed to open MediaMetadataRetriever for uri=" + uri, e);
|
||||
// unsupported format
|
||||
return null;
|
||||
}
|
||||
return retriever;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue