aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Message.java3
-rw-r--r--src/main/java/de/pixart/messenger/persistance/FileBackend.java32
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;