I'm working on an app where the user can see all the video's information and title that are stored on a SERVER. I'm almost done with it except that no matter how I code it, I cannot get the video duration from a given URL. Lets take this demo video from somewhere on the internet: CLICK HERE FOR VIDEO PATH I want the app to get the video duration without the need to open the video itself.
The Code that I'm trying to use on android is this:
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource("https://12-lvl3-pdl.vimeocdn.com/01/1386/0/6932347/10573836.mp4?expires=1461047937&token=037972137fdfc4c2d9902");
String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
long timeInmillisec = Long.parseLong( time );
long duration = timeInmillisec / 1000;
long hours = duration / 3600;
long minutes = (duration - hours * 3600) / 60;
long seconds = duration - (hours * 3600 + minutes * 60);
Toast.makeText(context,Long.toString(timeInmillisec),Toast.LENGTH_SHORT).show();
But the result that i'm getting is an: java.lang.IllegalArgumentException at line 2 which is " retriever.setDataSource() ". Can anyone help me find what i'm doing wrong or does android provide another way to get the required information?
setDataSource
it on MainThread or network thread ? – Jardena