I would like to confirm that what I am doing is really true, as some elements behave unexpectedly.
Firstly, I have a landscape and a portrait layout, as I understand it, this will automatically determine if the phone is in portrait / landscape mode:
- layout
- activity_video_player.xml
- layout-land
- activity_video_player.xml
Then, when a user selects a video from the gallery, I check if the video takes a landscape or portrait by doing this (inside OnCreate):
int w;
int h;
MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
mediaMetadataRetriever.setDataSource(this, videoURI);
String height = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
String width = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
w = Integer.parseInt(width);
h = Integer.parseInt(height);
if (w > h) {
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
I tested this and it works fine, but I noticed that some of my xml elements (play button) are not placed correctly.
So, the flow of my application:
MainActivity --> SelectvidButton --> Gallery Intent --> VideoPlayActivity
My question
This is the right way to do this, and if so, is there a reason why some xml elements do not fit correctly?
EDIT 1:
, , , "" , , .
2:
, , (MainActivity) , .