From 7e93f4519a2cf2df98d6a2a3fda07cb9a93f0502 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 12 Nov 2017 19:20:35 +0100 Subject: [PATCH] catch all RuntimeExceptions when using MetadataRetriever --- .../siacs/conversations/persistance/FileBackend.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 51eb6d0a1..74560c71f 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -485,7 +485,7 @@ public class FileBackend { frame = metadataRetriever.getFrameAtTime(0); metadataRetriever.release(); frame = resize(frame, size); - } catch(IllegalArgumentException | NullPointerException e) { + } catch(RuntimeException e) { frame = Bitmap.createBitmap(size,size, Bitmap.Config.ARGB_8888); frame.eraseColor(0xff000000); } @@ -819,7 +819,7 @@ public class FileBackend { MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever(); mediaMetadataRetriever.setDataSource(file.toString()); return Integer.parseInt(mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)); - } catch (IllegalArgumentException e) { + } catch (RuntimeException e) { return 0; } } @@ -839,7 +839,7 @@ public class FileBackend { MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever(); try { metadataRetriever.setDataSource(file.getAbsolutePath()); - } catch (Exception e) { + } catch (RuntimeException e) { throw new NotAVideoFile(e); } return getVideoDimensions(metadataRetriever); @@ -847,7 +847,11 @@ public class FileBackend { private static Dimensions getVideoDimensions(Context context, Uri uri) throws NotAVideoFile { MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever(); - mediaMetadataRetriever.setDataSource(context,uri); + try { + mediaMetadataRetriever.setDataSource(context, uri); + } catch (RuntimeException e) { + throw new NotAVideoFile(e); + } return getVideoDimensions(mediaMetadataRetriever); }