info: always show metadata from MediaMetadataRetriever for videos
This commit is contained in:
parent
1ae633dede
commit
d2c11f2d92
1 changed files with 15 additions and 14 deletions
|
@ -19,7 +19,6 @@ import com.adobe.internal.xmp.XMPMeta;
|
||||||
import com.adobe.internal.xmp.properties.XMPProperty;
|
import com.adobe.internal.xmp.properties.XMPProperty;
|
||||||
import com.adobe.internal.xmp.properties.XMPPropertyInfo;
|
import com.adobe.internal.xmp.properties.XMPPropertyInfo;
|
||||||
import com.drew.imaging.ImageMetadataReader;
|
import com.drew.imaging.ImageMetadataReader;
|
||||||
import com.drew.imaging.ImageProcessingException;
|
|
||||||
import com.drew.lang.GeoLocation;
|
import com.drew.lang.GeoLocation;
|
||||||
import com.drew.metadata.Directory;
|
import com.drew.metadata.Directory;
|
||||||
import com.drew.metadata.Metadata;
|
import com.drew.metadata.Metadata;
|
||||||
|
@ -143,22 +142,24 @@ public class MetadataHandler implements MethodChannel.MethodCallHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception | NoClassDefFoundError e) {
|
||||||
|
Log.w(LOG_TAG, "failed to get video metadata by ImageMetadataReader for uri=" + uri, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> videoDir = getVideoMetadataByRetriever(uri);
|
||||||
|
if (!videoDir.isEmpty()) {
|
||||||
|
metadataMap.put("Video", videoDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (metadataMap.isEmpty()) {
|
||||||
|
result.error("getAllMetadata-failure", "failed to get metadata for uri=" + uri, null);
|
||||||
|
} else {
|
||||||
result.success(metadataMap);
|
result.success(metadataMap);
|
||||||
} catch (ImageProcessingException | NoClassDefFoundError e) {
|
|
||||||
getAllVideoMetadataFallback(call, result);
|
|
||||||
} catch (Exception e) {
|
|
||||||
result.error("getAllMetadata-exception", "failed to get metadata for uri=" + uri, e.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getAllVideoMetadataFallback(MethodCall call, MethodChannel.Result result) {
|
private Map<String, String> getVideoMetadataByRetriever(String uri) {
|
||||||
String uri = call.argument("uri");
|
|
||||||
|
|
||||||
Map<String, Map<String, String>> metadataMap = new HashMap<>();
|
|
||||||
Map<String, String> dirMap = new HashMap<>();
|
Map<String, String> dirMap = new HashMap<>();
|
||||||
// unnamed fallback directory
|
|
||||||
metadataMap.put("", dirMap);
|
|
||||||
|
|
||||||
MediaMetadataRetriever retriever = StorageUtils.openMetadataRetriever(context, Uri.parse(uri));
|
MediaMetadataRetriever retriever = StorageUtils.openMetadataRetriever(context, Uri.parse(uri));
|
||||||
try {
|
try {
|
||||||
for (Map.Entry<Integer, String> kv : Constants.MEDIA_METADATA_KEYS.entrySet()) {
|
for (Map.Entry<Integer, String> kv : Constants.MEDIA_METADATA_KEYS.entrySet()) {
|
||||||
|
@ -176,13 +177,13 @@ public class MetadataHandler implements MethodChannel.MethodCallHandler {
|
||||||
dirMap.put(kv.getValue(), value);
|
dirMap.put(kv.getValue(), value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.success(metadataMap);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result.error("getAllVideoMetadataFallback-exception", "failed to get metadata for uri=" + uri, e.getMessage());
|
Log.w(LOG_TAG, "failed to get video metadata by MediaMetadataRetriever for uri=" + uri, e);
|
||||||
} finally {
|
} finally {
|
||||||
// cannot rely on `MediaMetadataRetriever` being `AutoCloseable` on older APIs
|
// cannot rely on `MediaMetadataRetriever` being `AutoCloseable` on older APIs
|
||||||
retriever.release();
|
retriever.release();
|
||||||
}
|
}
|
||||||
|
return dirMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCatalogMetadata(MethodCall call, MethodChannel.Result result) {
|
private void getCatalogMetadata(MethodCall call, MethodChannel.Result result) {
|
||||||
|
|
Loading…
Reference in a new issue