TOP
TOP

Reputation: 2614

What is the best way to get duration of a GIF in Java Android?

I'm finding the way to get duration of a GiF. Is there any function like getDuration() for Gif?

Upvotes: 2

Views: 3200

Answers (2)

Vivek Thummar
Vivek Thummar

Reputation: 413

Answer given by @samgak was working perfectly, and it works if input video is from assets (raw) folder.

But if we have input video path from device storage then just pass videoPath to Movie class like below:

Movie movie = Movie.decodeStream(videoPath);
int duration = movie.duration();

and it works fine (for me it's working very well, just a little problem is that it takes a little longer to calculate duration).

Upvotes: 0

samgak
samgak

Reputation: 24417

You could open the GIF as a Movie and check the duration:

    InputStream is = getResources().openRawResource(R.raw.my_gif);
    Movie movie = Movie.decodeStream(is);
    int duration = movie.duration();

Duration is in milliseconds.

Upvotes: 9

Related Questions