diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-09-24 20:40:21 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-09-24 20:40:21 +0200 |
commit | 259d29518331c4517c36e2baf073615fb7bf193f (patch) | |
tree | 700efff52fcf3f1bed0b35266cde53465e4d9582 /src/main | |
parent | 1f91140e949bfe3d1c7a053527b76a30d24ac294 (diff) |
reworked file params to store audio runtime amoung other things
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/de/pixart/messenger/entities/Message.java | 3 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/persistance/FileBackend.java | 32 |
2 files changed, 23 insertions, 12 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Message.java b/src/main/java/de/pixart/messenger/entities/Message.java index 95a08500c..af8c2aafa 100644 --- a/src/main/java/de/pixart/messenger/entities/Message.java +++ b/src/main/java/de/pixart/messenger/entities/Message.java @@ -726,6 +726,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]); @@ -793,6 +795,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/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java index 62153cb48..7be0492bb 100644 --- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java @@ -825,26 +825,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) { @@ -857,6 +855,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; |