Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine video width and height on Android

Tags:

I have a video file and I want to get width and height of video. I don't want to play it, just to get size. I've tried to use MediaPlayer:

MediaPlayer mp = new MediaPlayer(); mp.setDataSource(uriString); mp.prepare(); int width = mp.getVideoWidth(); int height = mp.getVideoHeight(); 

but it returns 0 for width and height, because VideoSizeChangedEvent didn't fire yet. How can I get width and height of video?

UPD: I need API version 7

like image 471
mao Avatar asked Jan 31 '12 09:01

mao


People also ask

How to get video width and height in Android studio?

MediaPlayer mp = new MediaPlayer(); mp. setDataSource(uriString); mp. prepare(); int width = mp. getVideoWidth(); int height = mp.

What is width and height of video?

The width and height of videos are usually measured in pixels and are collectively termed as the "dimensions" of the video. Thus, if a video is 320 pixels wide and 240 pixels in height, it is said to have dimensions of 320 x 240 pixels.


1 Answers

This works in API level 10 and up:

MediaMetadataRetriever retriever = new MediaMetadataRetriever(); retriever.setDataSource("/path/to/video.mp4"); int width = Integer.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)); int height = Integer.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)); retriever.release(); 
like image 53
Jarett Millard Avatar answered Oct 21 '22 08:10

Jarett Millard