I'm currently detecting the width and height of a selected video by doing the following:
MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
mediaMetadataRetriever.setDataSource(this, mVideoUri);
String height = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
String width = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
The activity in manifest:
<activity android:name=".TrimVideoActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen"
/>
If I toast the the width and height it always returns w : 1920 h : 1080
no matter what the dimensions of the video are. I think it is returning the width and height of the device instead.
Is there something that I'm missing or doing wrong?
EDIT
By following the link that @VladMatvienko suggested I was able to get the correct width and height of the video file, this is how I implemented it:
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
Bitmap bmp = null;
retriever.setDataSource(this, mVideoUri);
bmp = retriever.getFrameAtTime();
String videoWidth = String.valueOf(bmp.getWidth());
String videoHeight = String.valueOf(bmp.getHeight());
Now I want to rotate the screen depending on the result (width/height), I tried it by doing the following:
int w = Integer.parseInt(videoWidth);
int h = Integer.parseInt(videoHeight);
if (w > h) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} if(w < h) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
But, the screen always gets rotated to landscape, instead of being set to portrait when the width is smaller than the height?