aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-05-02 21:39:10 +0200
committerChristian Schneppe <christian@pix-art.de>2018-05-02 21:41:42 +0200
commitec81d7b2e1c428069bfb11c861b76b36aad23fe7 (patch)
tree471b73e2bec8fa76d5814863ef5c62016f1c6255 /src
parent218f3d0ed3c65eb16bae6e189a3cc2c46fdaff31 (diff)
get video dimensions from bitmap instead of meta data
Diffstat (limited to 'src')
-rw-r--r--src/main/java/de/pixart/messenger/persistance/FileBackend.java36
-rw-r--r--src/main/java/de/pixart/messenger/ui/ShowFullscreenMessageActivity.java16
2 files changed, 38 insertions, 14 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
index 4e959a868..c4107e863 100644
--- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java
+++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
@@ -1031,11 +1031,29 @@ public class FileBackend {
return getVideoDimensions(mediaMetadataRetriever);
}
+ private static Dimensions getVideoDimensionsOfFrame(MediaMetadataRetriever mediaMetadataRetriever) {
+ Bitmap bitmap = null;
+ try {
+ bitmap = mediaMetadataRetriever.getFrameAtTime();
+ return new Dimensions(bitmap.getHeight(), bitmap.getWidth());
+ } catch (Exception e) {
+ return null;
+ } finally {
+ if (bitmap != null) {
+ bitmap.recycle();
+ }
+ }
+ }
+
private static Dimensions getVideoDimensions(MediaMetadataRetriever metadataRetriever) throws NotAVideoFile {
String hasVideo = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_HAS_VIDEO);
if (hasVideo == null) {
throw new NotAVideoFile();
}
+ Dimensions dimensions = getVideoDimensionsOfFrame(metadataRetriever);
+ if (dimensions != null) {
+ return dimensions;
+ }
int rotation = extractRotationFromMediaRetriever(metadataRetriever);
boolean rotated = rotation == 90 || rotation == 270;
int height;
@@ -1058,25 +1076,19 @@ public class FileBackend {
}
private static int extractRotationFromMediaRetriever(MediaMetadataRetriever metadataRetriever) {
- int rotation;
- if (Build.VERSION.SDK_INT >= 17) {
- String r = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);
- try {
- rotation = Integer.parseInt(r);
- } catch (Exception e) {
- rotation = 0;
- }
- } else {
- rotation = 0;
+ String r = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);
+ try {
+ return Integer.parseInt(r);
+ } catch (Exception e) {
+ return 0;
}
- return rotation;
}
private static class Dimensions {
public final int width;
public final int height;
- public Dimensions(int height, int width) {
+ Dimensions(int height, int width) {
this.width = width;
this.height = height;
}
diff --git a/src/main/java/de/pixart/messenger/ui/ShowFullscreenMessageActivity.java b/src/main/java/de/pixart/messenger/ui/ShowFullscreenMessageActivity.java
index d4528f962..f8ded022e 100644
--- a/src/main/java/de/pixart/messenger/ui/ShowFullscreenMessageActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ShowFullscreenMessageActivity.java
@@ -5,6 +5,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
+import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.MediaMetadataRetriever;
import android.net.Uri;
@@ -185,8 +186,19 @@ public class ShowFullscreenMessageActivity extends XmppActivity {
private void DisplayVideo(final Uri uri) {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(uri.getPath());
- height = Integer.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
- width = Integer.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
+ Bitmap bitmap = null;
+ try {
+ bitmap = retriever.getFrameAtTime();
+ height = bitmap.getHeight();
+ width = bitmap.getWidth();
+ } catch (Exception e) {
+ height = Integer.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
+ width = Integer.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
+ } finally {
+ if (bitmap != null) {
+ bitmap.recycle();
+ }
+ }
rotation = Integer.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION));
Log.d(Config.LOGTAG, "Video height: " + height + ", width: " + width + ", rotation: " + rotation);
if (useAutoRotateScreen()) {