From 30b6201b95e86fb9862e19eb255d2f7c223aeaab Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 19 Sep 2017 22:42:22 +0200 Subject: [PATCH] reworked file params to store audio runtime amoung other things --- .../siacs/conversations/entities/Message.java | 3 ++ .../persistance/FileBackend.java | 32 ++++++++++++------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java index cc594d1c2..df8774110 100644 --- a/src/main/java/eu/siacs/conversations/entities/Message.java +++ b/src/main/java/eu/siacs/conversations/entities/Message.java @@ -715,6 +715,8 @@ public class Message extends AbstractEntity { fileParams.url = parseUrl(parts[0]); } break; + case 5: + fileParams.runtime = parseInt(parts[4]); case 4: fileParams.width = parseInt(parts[2]); fileParams.height = parseInt(parts[3]); @@ -778,6 +780,7 @@ public class Message extends AbstractEntity { public long size = 0; public int width = 0; public int height = 0; + public int runtime = 0; } public void setFingerprint(String fingerprint) { diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index ce2a0f84a..f6544fd0a 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -777,26 +777,24 @@ public class FileBackend { final String mime = file.getMimeType(); boolean image = message.getType() == Message.TYPE_IMAGE || (mime != null && mime.startsWith("image/")); boolean video = mime != null && mime.startsWith("video/"); + boolean audio = mime != null && mime.startsWith("audio/"); + final StringBuilder body = new StringBuilder(); + if (url != null) { + body.append(url.toString()); + } + body.append('|').append(file.getSize()); if (image || video) { try { Dimensions dimensions = image ? getImageDimensions(file) : getVideoDimensions(file); - if (url == null) { - message.setBody(Long.toString(file.getSize()) + '|' + dimensions.width + '|' + dimensions.height); - } else { - message.setBody(url.toString() + "|" + Long.toString(file.getSize()) + '|' + dimensions.width + '|' + dimensions.height); - } - return; + body.append('|').append(dimensions.width).append('|').append(dimensions.height); } catch (NotAVideoFile notAVideoFile) { Log.d(Config.LOGTAG,"file with mime type "+file.getMimeType()+" was not a video file"); //fall threw } + } else if (audio) { + body.append("|0|0|").append(getMediaRuntime(file)); } - if (url != null) { - message.setBody(url.toString()+"|"+Long.toString(file.getSize())); - } else { - message.setBody(Long.toString(file.getSize())); - } - + message.setBody(body.toString()); } public int getMediaRuntime(Uri uri) { @@ -809,6 +807,16 @@ public class FileBackend { } } + private int getMediaRuntime(File file) { + try { + MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever(); + mediaMetadataRetriever.setDataSource(file.toString()); + return Integer.parseInt(mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)); + } catch (IllegalArgumentException e) { + return 0; + } + } + private Dimensions getImageDimensions(File file) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;