MediaMetadataRetriever retriever = new MediaMetadataRetriever(); retriever.setDataSource(your_data_source); String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); long timeInmillisec = Long.parseLong( time );
References
https://stackoverflow.com/questions/24014330/how-can-i-get-a-video-duration-before-without-playing