How to get video file details eg. duration in Android?
Posted
by
spirytus
on Stack Overflow
See other posts from Stack Overflow
or by spirytus
Published on 2012-09-12T21:25:46Z
Indexed on
2012/09/12
21:38 UTC
Read the original article
Hit count: 360
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 cursor
with all the files, then loop one by one.
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();
}
I need however to access details of specific files so I tried to create URI
but no luck as cursor
returned is always null
. Where do I go wrong?
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
© Stack Overflow or respective owner