diff options
Diffstat (limited to 'src/main/java/de/pixart/messenger/persistance')
-rw-r--r-- | src/main/java/de/pixart/messenger/persistance/FileBackend.java | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java index ee645c50b..62153cb48 100644 --- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java @@ -169,6 +169,18 @@ public class FileBackend { return true; //exception to be compatible with HTTP Upload < v0.2 } for (Uri uri : uris) { + String mime = context.getContentResolver().getType(uri); + if (mime != null && mime.startsWith("video/")) { + try { + Dimensions dimensions = FileBackend.getVideoDimensions(context, uri); + if (dimensions.getMin() >= 720) { + Log.d(Config.LOGTAG, "do not consider video file with min width larger or equal than 720 for size check"); + continue; + } + } catch (NotAVideoFile notAVideoFile) { + //ignore and fall through + } + } if (FileBackend.getFileSize(context, uri) > max) { Log.d(Config.LOGTAG, "not all files are under " + max + " bytes. suggesting falling back to jingle"); return false; @@ -863,6 +875,17 @@ public class FileBackend { } catch (Exception e) { throw new NotAVideoFile(); } + return getVideoDimensions(metadataRetriever); + } + + + private static Dimensions getVideoDimensions(Context context, Uri uri) throws NotAVideoFile { + MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever(); + mediaMetadataRetriever.setDataSource(context, uri); + return getVideoDimensions(mediaMetadataRetriever); + } + + private static Dimensions getVideoDimensions(MediaMetadataRetriever metadataRetriever) throws NotAVideoFile { String hasVideo = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_HAS_VIDEO); if (hasVideo == null) { throw new NotAVideoFile(); @@ -888,7 +911,7 @@ public class FileBackend { return rotated ? new Dimensions(width, height) : new Dimensions(height, width); } - private int extractRotationFromMediaRetriever(MediaMetadataRetriever metadataRetriever) { + private static int extractRotationFromMediaRetriever(MediaMetadataRetriever metadataRetriever) { int rotation; if (Build.VERSION.SDK_INT >= 17) { String r = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION); @@ -903,7 +926,7 @@ public class FileBackend { return rotation; } - private class Dimensions { + private static class Dimensions { public final int width; public final int height; @@ -911,9 +934,13 @@ public class FileBackend { this.width = width; this.height = height; } + + public int getMin() { + return Math.min(width, height); + } } - private class NotAVideoFile extends Exception { + private static class NotAVideoFile extends Exception { } |