List of usage examples for android.media MediaMetadataRetriever METADATA_KEY_VIDEO_HEIGHT
int METADATA_KEY_VIDEO_HEIGHT
To view the source code for android.media MediaMetadataRetriever METADATA_KEY_VIDEO_HEIGHT.
Click Source Link
From source file:de.lebenshilfe_muenster.uk_gebaerden_muensterland.sign_video_view.AbstractSignVideoFragment.java
private void setVideoViewDimensionToMatchVideoMetadata(VideoView videoView, Uri uri) { String metadataVideoWidth;/* ww w . j av a2 s. c o m*/ String metadataVideoHeight; try { final MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever(); metaRetriever.setDataSource(getActivity(), uri); metadataVideoWidth = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH); metadataVideoHeight = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT); metaRetriever.release(); Validate.notEmpty(metadataVideoWidth); Validate.notEmpty(metadataVideoHeight); } catch (NullPointerException | IllegalArgumentException ex) { throw new VideoSetupException(getActivity().getString(R.string.ASVF_2) + ex.getLocalizedMessage(), ex); } if (null == metadataVideoWidth) { throw new VideoSetupException(getActivity().getString(R.string.ASVF_3)); } if (null == metadataVideoHeight) { throw new VideoSetupException(getActivity().getString(R.string.ASVF_4)); } final double videoWidth = Double.valueOf(metadataVideoWidth); final double videoHeight = Double.valueOf(metadataVideoHeight); final double videoRatio = videoWidth / videoHeight; Log.d(TAG, String.format("videoWidth: %s, videoHeight: %s, videoRatio: %s", videoWidth, videoHeight, videoRatio)); boolean isOrientationPortrait = Configuration.ORIENTATION_PORTRAIT == getResources() .getConfiguration().orientation; int displayHeight = getResources().getDisplayMetrics().heightPixels; int displayWidth = getResources().getDisplayMetrics().widthPixels; Log.d(TAG, String.format("displayHeight: %s, displayWidth: %s", displayHeight, displayWidth)); final double desiredVideoWidth, desiredVideoHeight; if (isOrientationPortrait) { desiredVideoWidth = displayWidth * MAXIMUM_VIDEO_WIDTH_ON_PORTRAIT; desiredVideoHeight = 1 / (videoRatio / desiredVideoWidth); Log.d(TAG, String.format("OrientationPortrait: desiredVideoWidth: %s, desiredVideoHeight: %s", desiredVideoWidth, desiredVideoHeight)); } else { // orientation is Landscape desiredVideoHeight = displayHeight * MAXMIMUM_VIDEO_HEIGHT_ON_LANDSCAPE; desiredVideoWidth = desiredVideoHeight * videoRatio; Log.d(TAG, String.format("OrientationLandscape: desiredVideoWidth: %s, desiredVideoHeight: %s", desiredVideoWidth, desiredVideoHeight)); } final ViewGroup.LayoutParams layoutParams = videoView.getLayoutParams(); layoutParams.width = (int) desiredVideoWidth; layoutParams.height = (int) desiredVideoHeight; }