get video duration from URL in android app -


i'm working on app user can see video's information , title stored on server. i'm done except no matter how code it, cannot video duration given url. lets take demo video somewhere on internet: click here video path want app video duration without need open video itself.

the code i'm trying use on android 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 result i'm getting an: java.lang.illegalargumentexception @ line 2 " retriever.setdatasource() ". can me find i'm doing wrong or android provide way required information?

maybe looking ffmpegmediametadataretriever

ffmpegmediametadataretriever class provides unified interface retrieving frame , metadata input media file.

by using metadata_key_duration constant of ffmpegmediametadataretriever can duration of video.it return string can convert long time.

here code should use:

ffmpegmediametadataretriever mffmpegmediametadataretriever = new mediametadataretriever(); mffmpegmediametadataretriever .setdatasource("your video url"); string mvideoduration =  mffmpegmediametadataretriever .extractmetadata(ffmpegmediametadataretriever .metadata_key_duration); long mtimeinmilliseconds= long.parselong(mvideoduration); 

if above still not work use

mediametadataretriever retriever = new mediametadataretriever(); if (build.version.sdk_int >= 14)  retriever.setdatasource("your video url", new hashmap<string, string>()); else  retriever.setdatasource("your video url"); 

from code.

hope you. best of luck.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -