1

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?

Ashin Mandal
  • 463
  • 1
  • 6
  • 19

1 Answers1

1

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.

Nishant Rajput
  • 2,053
  • 16
  • 28
  • 1
    So, should I not use File[] at all and use Cursor instead? 'managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,proj,null,null,null);' Does this method fetch all the videos in the SD Card? I want all the videos only from a particular directory in the SD Card. – Ashin Mandal Apr 23 '12 at 11:37
  • Just to let everyone know that the duration is in milliseconds. – Ashin Mandal Apr 24 '12 at 07:22
  • hi i am using same code,but i am getting duration 0 each time after recording video.Is it because i have recorded video recently and its content data is not available?Please help me if any one have solution for same issue. – chikka.anddev May 21 '12 at 14:08
  • how to use it with fileList[i]? – NickUnuchek Aug 27 '15 at 09:05