How to know duration of any media file
<p>My application shows list of media(audio and Video) files in the sdcard along with file size,mime type. I now want to add total duration of the media file in the every list item.
I tried fetching the duration using following code </p>

<pre><code>String[] proj = { MediaStore.Video.VideoColumns.DURATION };
 Cursor cursor = managedQuery(contentUri, proj, null, null, null);
 int column_index
  = cursor.getColumnIndexOrThrow(MediaStore.Video.VideoColumns.DURATION);
</code></pre>

<p>but <code>MediaStore</code> returns correct duration only if the media is played before, if not it returns 0. I cannot use <code>videoview.getDuration</code> since I don't want to play the video. 
I want your help to know if I am making any mistake in above code or if there is any other way to fetch duration <strong>without playing it first</strong>.</p>
