aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-07-22 16:32:38 +0200
committerChristian Schneppe <christian@pix-art.de>2016-07-25 19:45:52 +0200
commit5a6d3878a275ddfd5c30b75928cf0b3b123cdb25 (patch)
tree712e5335f6cc63b0c83e8a20d3646fc8bb0b34eb /src/main/java/eu/siacs/conversations
parent484068e14349d9e00879c6028f616729e66e4229 (diff)
provide black background video thumbnail if preview couldn't be generated
Diffstat (limited to 'src/main/java/eu/siacs/conversations')
-rw-r--r--src/main/java/eu/siacs/conversations/persistance/FileBackend.java19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
index 9ef92a07e..6d4fdba0e 100644
--- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
+++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
@@ -432,10 +432,16 @@ public class FileBackend {
private Bitmap getVideoPreview(File file, int size) {
MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever();
- metadataRetriever.setDataSource(file.getAbsolutePath());
- Bitmap frame = metadataRetriever.getFrameAtTime(0);
- metadataRetriever.release();
- frame = resize(frame, size);
+ Bitmap frame;
+ try {
+ metadataRetriever.setDataSource(file.getAbsolutePath());
+ frame = metadataRetriever.getFrameAtTime(0);
+ metadataRetriever.release();
+ frame = resize(frame, size);
+ } catch(IllegalArgumentException e) {
+ frame = Bitmap.createBitmap(size,size, Bitmap.Config.ARGB_8888);
+ frame.eraseColor(0xff000000);
+ }
Canvas canvas = new Canvas(frame);
Bitmap play = BitmapFactory.decodeResource(mXmppConnectionService.getResources(), R.drawable.play_video);
float x = (frame.getWidth() - play.getWidth()) / 2.0f;
@@ -705,8 +711,9 @@ public class FileBackend {
public void updateFileParams(Message message, URL url) {
DownloadableFile file = getFile(message);
- boolean image = message.getType() == Message.TYPE_IMAGE || file.getMimeType().startsWith("image/");
- boolean video = message.getMimeType().startsWith("video/");
+ final String mime = file.getMimeType();
+ boolean image = message.getType() == Message.TYPE_IMAGE || (mime != null && mime.startsWith("image/"));
+ boolean video = mime != null && mime.startsWith("video/");
if (image || video) {
try {
Dimensions dimensions = image ? getImageDimensions(file) : getVideoDimensions(file);