provide black background video thumbnail if preview couldn't be generated

This commit is contained in:
Daniel Gultsch 2016-07-22 16:32:38 +02:00
parent e9c00c0427
commit 3a5735e717
1 changed files with 13 additions and 6 deletions

View File

@ -406,10 +406,16 @@ public class FileBackend {
private Bitmap getVideoPreview(File file, int size) { private Bitmap getVideoPreview(File file, int size) {
MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever(); MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever();
Bitmap frame;
try {
metadataRetriever.setDataSource(file.getAbsolutePath()); metadataRetriever.setDataSource(file.getAbsolutePath());
Bitmap frame = metadataRetriever.getFrameAtTime(0); frame = metadataRetriever.getFrameAtTime(0);
metadataRetriever.release(); metadataRetriever.release();
frame = resize(frame, size); frame = resize(frame, size);
} catch(IllegalArgumentException e) {
frame = Bitmap.createBitmap(size,size, Bitmap.Config.ARGB_8888);
frame.eraseColor(0xff000000);
}
Canvas canvas = new Canvas(frame); Canvas canvas = new Canvas(frame);
Bitmap play = BitmapFactory.decodeResource(mXmppConnectionService.getResources(), R.drawable.play_video); Bitmap play = BitmapFactory.decodeResource(mXmppConnectionService.getResources(), R.drawable.play_video);
float x = (frame.getWidth() - play.getWidth()) / 2.0f; float x = (frame.getWidth() - play.getWidth()) / 2.0f;
@ -679,8 +685,9 @@ public class FileBackend {
public void updateFileParams(Message message, URL url) { public void updateFileParams(Message message, URL url) {
DownloadableFile file = getFile(message); DownloadableFile file = getFile(message);
boolean image = message.getType() == Message.TYPE_IMAGE || file.getMimeType().startsWith("image/"); final String mime = file.getMimeType();
boolean video = message.getMimeType().startsWith("video/"); boolean image = message.getType() == Message.TYPE_IMAGE || (mime != null && mime.startsWith("image/"));
boolean video = mime != null && mime.startsWith("video/");
if (image || video) { if (image || video) {
try { try {
Dimensions dimensions = image ? getImageDimensions(file) : getVideoDimensions(file); Dimensions dimensions = image ? getImageDimensions(file) : getVideoDimensions(file);