diff options
author | Christian Schneppe <christian@pix-art.de> | 2016-05-22 21:30:38 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2016-05-22 21:30:38 +0200 |
commit | cf956b605c459bd8d8e08ced00a06207bbd8cdc4 (patch) | |
tree | 017645d1acdbe5b8cb1514fae119bc5eba36332c /src/main | |
parent | 3ac225b04062af5b6c67f7f79a1219932d15b1dc (diff) |
catch exception on videopreview
Diffstat (limited to '')
-rw-r--r-- | src/main/java/eu/siacs/conversations/ui/XmppActivity.java | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index d582ba592..2a6dbf589 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -1191,23 +1191,27 @@ public abstract class XmppActivity extends Activity { public void loadVideoPreview(Message message, ImageView imageView) { File vp = xmppConnectionService.getFileBackend().getFile(message, true); - MediaMetadataRetriever retriever = new MediaMetadataRetriever(); - //use one of overloaded setDataSource() functions to set your data source - retriever.setDataSource(this, Uri.fromFile(vp)); - String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); - long microSecond = Long.parseLong(time); - int duration = (int) microSecond / 2; //preview at half of video - BitmapPool bitmapPool = Glide.get(getApplicationContext()).getBitmapPool(); - VideoBitmapDecoder videoBitmapDecoder = new VideoBitmapDecoder(duration); - FileDescriptorBitmapDecoder fileDescriptorBitmapDecoder = new FileDescriptorBitmapDecoder(videoBitmapDecoder, bitmapPool, DecodeFormat.PREFER_ARGB_8888); - Glide.with(getApplicationContext()) - .load(vp) - .asBitmap() - .override(400, 400) - .fitCenter() - //.centerCrop() - .diskCacheStrategy(DiskCacheStrategy.RESULT) - .videoDecoder(fileDescriptorBitmapDecoder) - .into(imageView); + try { + MediaMetadataRetriever retriever = new MediaMetadataRetriever(); + //use one of overloaded setDataSource() functions to set your data source + retriever.setDataSource(this, Uri.fromFile(vp)); + String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); + long microSecond = Long.parseLong(time); + int duration = (int) microSecond / 2; //preview at half of video + BitmapPool bitmapPool = Glide.get(getApplicationContext()).getBitmapPool(); + VideoBitmapDecoder videoBitmapDecoder = new VideoBitmapDecoder(duration); + FileDescriptorBitmapDecoder fileDescriptorBitmapDecoder = new FileDescriptorBitmapDecoder(videoBitmapDecoder, bitmapPool, DecodeFormat.PREFER_ARGB_8888); + Glide.with(getApplicationContext()) + .load(vp) + .asBitmap() + .override(400, 400) + .fitCenter() + //.centerCrop() + .diskCacheStrategy(DiskCacheStrategy.RESULT) + .videoDecoder(fileDescriptorBitmapDecoder) + .into(imageView); + } catch (Exception e) { + e.printStackTrace(); + } } } |