reworked file params to store audio runtime amoung other things

This commit is contained in:
Daniel Gultsch 2017-09-19 22:42:22 +02:00
parent 9733003d0f
commit 30b6201b95
2 changed files with 23 additions and 12 deletions

View File

@ -715,6 +715,8 @@ public class Message extends AbstractEntity {
fileParams.url = parseUrl(parts[0]); fileParams.url = parseUrl(parts[0]);
} }
break; break;
case 5:
fileParams.runtime = parseInt(parts[4]);
case 4: case 4:
fileParams.width = parseInt(parts[2]); fileParams.width = parseInt(parts[2]);
fileParams.height = parseInt(parts[3]); fileParams.height = parseInt(parts[3]);
@ -778,6 +780,7 @@ public class Message extends AbstractEntity {
public long size = 0; public long size = 0;
public int width = 0; public int width = 0;
public int height = 0; public int height = 0;
public int runtime = 0;
} }
public void setFingerprint(String fingerprint) { public void setFingerprint(String fingerprint) {

View File

@ -777,26 +777,24 @@ public class FileBackend {
final String mime = file.getMimeType(); final String mime = file.getMimeType();
boolean image = message.getType() == Message.TYPE_IMAGE || (mime != null && mime.startsWith("image/")); boolean image = message.getType() == Message.TYPE_IMAGE || (mime != null && mime.startsWith("image/"));
boolean video = mime != null && mime.startsWith("video/"); 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) { if (image || video) {
try { try {
Dimensions dimensions = image ? getImageDimensions(file) : getVideoDimensions(file); Dimensions dimensions = image ? getImageDimensions(file) : getVideoDimensions(file);
if (url == null) { body.append('|').append(dimensions.width).append('|').append(dimensions.height);
message.setBody(Long.toString(file.getSize()) + '|' + dimensions.width + '|' + dimensions.height);
} else {
message.setBody(url.toString() + "|" + Long.toString(file.getSize()) + '|' + dimensions.width + '|' + dimensions.height);
}
return;
} catch (NotAVideoFile notAVideoFile) { } catch (NotAVideoFile notAVideoFile) {
Log.d(Config.LOGTAG,"file with mime type "+file.getMimeType()+" was not a video file"); Log.d(Config.LOGTAG,"file with mime type "+file.getMimeType()+" was not a video file");
//fall threw //fall threw
} }
} else if (audio) {
body.append("|0|0|").append(getMediaRuntime(file));
} }
if (url != null) { message.setBody(body.toString());
message.setBody(url.toString()+"|"+Long.toString(file.getSize()));
} else {
message.setBody(Long.toString(file.getSize()));
}
} }
public int getMediaRuntime(Uri uri) { 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) { private Dimensions getImageDimensions(File file) {
BitmapFactory.Options options = new BitmapFactory.Options(); BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true; options.inJustDecodeBounds = true;