Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get length in milliseconds of video from URL without video view in Android?

Tags:

I am making a Media player in Android. I require a code to get length of video without using a video view.

I saw many pages in Stack overflow but ever page used to show how to get length of a video in video view but i require without video view.

like image 429
AngryBird Avatar asked Apr 28 '13 04:04

AngryBird


People also ask

How do I find the duration of a URL?

By using METADATA_KEY_DURATION constant of FFmpegMediaMetadataRetriever you can get the duration of your video.It will return the string to you then you can convert it into LONG to get TIME. MediaMetadataRetriever retriever = new MediaMetadataRetriever(); if (Build. VERSION.

What is duration on smartphone?

↳ java.time.Duration. A time-based amount of time, such as '34.5 seconds'. This class models a quantity or amount of time in terms of seconds and nanoseconds. It can be accessed using other duration-based units, such as minutes and hours.


1 Answers

You could use the MediaMetadataRetriever to get such an information. This class is meant to be used by users who wants to get specific informations about a media without having to use the MediaPlayer.

Here's a sample of how to use it :

MediaMetadataRetriever retriever = new MediaMetadataRetriever(); retriever.setDataSource(your_data_source); 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); 
like image 121
Halim Qarroum Avatar answered Oct 05 '22 21:10

Halim Qarroum