android - How can I get a video duration before/without playing -
videoview.setoncompletionlistener(new mediaplayer.oncompletionlistener() { @override public void oncompletion(mediaplayer mp) { videoview videoview = (videoview) findviewbyid(r.id.videoview1); long duration= videoview.getduration(); toast.maketext(getapplicationcontext(), "video completed", toast.length_long).show(); mshimmerdevice.stopstreaming(); mshimmerdevice.stop(); } }); }
though code works after video had finished playing
you use mediametadataretriever. way can retrieve information video without loading/playing it.
mediametadataretriever retriever = new mediametadataretriever(); retriever.setdatasource(your_data_source); string time = retriever.extractmetadata(mediametadataretriever.metadata_key_duration); long timeinmillisec = long.parselong( time );
Comments
Post a Comment