title: How to get video file details eg. duration in Android?
body: <p>I struggle to get specific video file details so duration etc. from the file the files recorded earlier. All I can currently do is to get <code>cursor</code> with all the files, then loop one by one. </p>
  
  <pre><code>Cursor cursor = MediaStore.Video.query(getContext().getContentResolver(), MediaStore.Video.Media.EXTERNAL_CONTENT_URI, new String[]{MediaStore.Video.VideoColumns.DURATION,MediaStore.Video.VideoColumns.DATE_TAKEN,MediaStore.Video.VideoColumns.RESOLUTION,MediaStore.Video.VideoColumns.DISPLAY_NAME});
  
  
                      if(cursor.moveToFirst())
                          while(!cursor.isLast()){
  
                                  if(cursor.getString(3)==fight.filename)
                                  {
                                      // do something here
                                  }
  
                                  cursor.moveToNext();
                          }
  </code></pre>
  
  <p>I need however to access details of specific files so I tried to create <code>URI</code> but no luck as <code>cursor</code> returned is always <code>null</code>. Where do I go wrong?</p>
  
  <pre><code>                Uri uri = Uri.parse(Environment.DIRECTORY_DCIM+"/FightAll_BJJ_Scoring/"+(fight.filename));
  
                  Cursor cursor = MediaStore.Video.query(getContext().getContentResolver(), uri, new String[]{MediaStore.Video.VideoColumns.DURATION,MediaStore.Video.VideoColumns.DATE_TAKEN,MediaStore.Video.VideoColumns.RESOLUTION,MediaStore.Video.VideoColumns.DISPLAY_NAME});
  
                  // cursor is always null here
  </code></pre>
  
  <p>EDIT: thanks to zapl answer below I got this code below (note that I modified cursor line), however now cursor returned is not null, but its still empty and when I try to read cursor.getString(2) I got nothing. </p>
  
  <pre><code>Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
                      String selection = MediaColumns.DATA + "=?";
                      String[] selectionArgs = { Environment.DIRECTORY_DCIM+"/FightAll_BJJ_Scoring/"+(fight.filename) };
                      Cursor cursor = getContext().getContentResolver().query(uri, new String[]{MediaStore.Video.VideoColumns.DURATION,MediaStore.Video.VideoColumns.DATE_TAKEN,MediaStore.Video.VideoColumns.RESOLUTION,MediaStore.Video.VideoColumns.DISPLAY_NAME}, selection, selectionArgs, null);
  </code></pre>
  
  <p>Any help will be much appreciated.</p>