I hope to get the duration, resolution of a video file of a video (.mp4), how can I do that programmatically in Android ? My minSdkVersion is 21 .
BTW, I can get the file size of a video using the following code.
String recVideoPath = Environment.getExternalStorageDirectory() + videoRecordedFileName;
File file = new File(recVideoPath);
long fileVideo = file.length();
Thanks!
To get duration and resolution MediaMetadataRetriever
could be used like:
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(uriOfFile);
long duration = Long.parseLong(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION))
int width = Integer.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
int height = Integer.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
retriever.release();
uriOfFile is a string with the url to you mp4.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With