diff options
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(); + } } } |