I'm trying to get the size of a remote video using this class and i'm getting IllegalArgumentException if the video is remote.
the video is an mp4 stored in one server...
the video plays correctly if i play it with mediaplayer, but it gives the error if i try to do this:
try {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
Bitmap bmp = null;
retriever.setDataSource(context, uri);
bmp = retriever.getFrameAtTime();
videoHeight = (int) (bmp.getHeight()*((float)getIntWidth()/bmp.getWidth()));
} catch (Exception e) {
e.printStackTrace();
}
the error is thrown in this line:
retriever.setDataSource(context, uri);
and uri contains Uri.parse("http://www.myweb.com/myvideo.mp4");
what is wrong in the code?
12-19 13:38:08.610: W/System.err(13333): java.lang.IllegalArgumentException
12-19 13:38:08.611: W/System.err(13333): at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:175)
Maybe you are running into this bug. If so try:
If that doesn't work you can always try FFmpegMediaMetadataRetriever:
In my case, I was creating a simple metadata extraction test app, so I copied a file to my phone using adb, like so:
but I forgot to add the read external storage directory permission in the app manifest.
Specifically:
Adding those permissions fixed it for me, even for the simple file string call:
And of course, if you're targeting API 23+ marshmallow then you'll have to dynamically ask for those permissions, as well.