Question

I am absolutely new to Android Development and am trying to create a small Video Player which can record videos and view recorded videos. I am viewing the list of videos recorded by the app in a ListView where for each video I show the title and length of the video.

I fetch a list of videos using:

File[] fileList = directory.listFiles(filter); 

I have been able to fetch the name of the video using the following:

fileList[i].getName()

But I can't seem to figure out how to extract the length/ duration of the video. I could not find any relevant APIs which does so as well.

How can I get the duration of a 3GP video file in Java?

Was it helpful?

Solution

you can use Cursor like this ...

 String[] proj = {
            MediaStore.Video.Media._ID,
            MediaStore.Video.Media.DATA,
            MediaStore.Video.Media.DISPLAY_NAME,
            MediaStore.Video.Media.SIZE,
            MediaStore.Video.Media.DATE_TAKEN,
            MediaStore.Video.Media.DURATION };

            videocursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,proj, null, null, null);

you can get Video file Duration using MediaStore.Video.Media.DURATION.

Hope it will help you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top