Search code examples
androidandroid-mediaplayermediastoremkv

Mediastore duration of MKV file returns 0


I am trying to fetch the duration of MKV file from mediastore . However, it returns me 0. If I use Mediaplayer MediaPlayer.create , media player is null and I get a error (-1,2147483648) with a message that prepare failed. I am able to fetch duration of other videos with extension mp4 .Something wrong with the path? Can anyone help?

1st method:

long duration = cursor.getLong(MediaStore.Video.VideoColumns.DURATION); This returns 0.

2nd method:

Uri uri = Uri.fromFile(new File(filePath)); 
MediaPlayer mp = MediaPlayer.create(TestApplication.getAppContext(), uri);

// uri is file:///storage/emulated/0/Movies/Test.MKV

This returns mp = null.

I also tried MediaMetadataRetriever but that also returned null. How can I get the duration?


Solution

  • Seems like the MKV file was corrupted. Hence, closing this.