mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-14 04:55:04 -05:00
reworked file params to store audio runtime amoung other things
This commit is contained in:
parent
9733003d0f
commit
30b6201b95
@ -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) {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user