I am looking for solution to get detail video information (like duration, video thumbnail...) from URL in Android?
-
It can't be taken until you load URL in your videoView OR you can receive this info from the server from where you are getting this url – Usman Rana Jul 13 '17 at 13:52
2 Answers
You are asking 2 different questions already answered here on StackOverflow.
To retrieve the video duration and other meta data, see this answer.
Maybe you are looking for the FFmpegMediaMetadataRetriever
FFmpegMediaMetadataRetriever class provides a unified interface for the retrieving frame and metadata from an input media file.
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.
Here is the code you 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 then 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");
To download the thumbnail, see this answer.
Without downloading video you can generate thumbnail from below code:
public static Bitmap retriveVideoFrameFromVideo(String videoPath) throws Throwable { Bitmap bitmap = null; MediaMetadataRetriever mediaMetadataRetriever = null; try { mediaMetadataRetriever = new MediaMetadataRetriever(); if (Build.VERSION.SDK_INT >= 14) mediaMetadataRetriever.setDataSource(videoPath, new HashMap<String, String>()); else mediaMetadataRetriever.setDataSource(videoPath); // mediaMetadataRetriever.setDataSource(videoPath); bitmap = mediaMetadataRetriever.getFrameAtTime(); } catch (Exception e) { e.printStackTrace(); throw new Throwable("Exception in retriveVideoFrameFromVideo(String videoPath)" + e.getMessage()); } finally { if (mediaMetadataRetriever != null) { mediaMetadataRetriever.release(); } } return bitmap; }
Both answers are for Android and does not require to download the whole video.

- 3,894
- 7
- 24
- 56
-
your answer (how to get video thumbnail from url) is giving this error ( status = 0x80000000 ). Why? I am trying to show video thumbnail from youtube. – Taras Stavnychyi Jul 13 '17 at 21:52
-
@TarasStavnychyi Getting thumbnail from a video and from a video service like Youtube is very different. However, since this code supports MP4, you can use this https://stackoverflow.com/questions/31566835/how-to-get-the-mp4-url-for-youtube-videos-using-youtube-v3-api to convert your Youtube URL to a mp4 url. – Winter Jul 14 '17 at 12:15
try this to get video thumbnail from url
public static Bitmap retriveVideoFrameFromVideo(String videoPath)
throws Throwable
{
Bitmap bitmap = null;
MediaMetadataRetriever mediaMetadataRetriever = null;
try
{
mediaMetadataRetriever = new MediaMetadataRetriever();
if (Build.VERSION.SDK_INT >= 14)
mediaMetadataRetriever.setDataSource(videoPath, new HashMap<String, String>());
else
mediaMetadataRetriever.setDataSource(videoPath);
// mediaMetadataRetriever.setDataSource(videoPath);
bitmap = mediaMetadataRetriever.getFrameAtTime();
}
catch (Exception e)
{
e.printStackTrace();
throw new Throwable(
"Exception in retriveVideoFrameFromVideo(String videoPath)"
+ e.getMessage());
}
finally
{
if (mediaMetadataRetriever != null)
{
mediaMetadataRetriever.release();
}
}
return bitmap;
}
credit goes to @nilesh Rathod

- 67,701
- 16
- 123
- 163