Tuesday, April 30, 2013

[android-developers] Re: To play gif from a file

I have played animated GIFs on Android before simply by loading them in a WebView.


On Tuesday, April 30, 2013 9:09:26 AM UTC-5, Beyza Nur Kökcan wrote:
I have found tutorials about how to play animated gifs in android by reading it from an asset or using a drawable object. But what I want is to read a gif file from sdcard. 
I have changed the project reading gif from assets a little bit.

In the main activity, I basically create gifMovieView then setContent(gifMovieView)
In the constructor of the GifMovieView class, I have initailized the Movie object like in the project "eu.andlabs.tutorial.animatedgifs". But I have used decodeFile giving the file path instead of decodeStream getting inputStream.

        File file = new File (Environment.getExternalStorageDirectory().getAbsolutePath(),"piggy.gif");
               mMovie = Movie.decodeFile(file.getPath()); 

I HAVE GİVEN I/O EXCEPTION for this line. It finds the file but decodeFile gives exception.

In onDraw ;

    protected void onDraw(Canvas canvas) {
        final long now = SystemClock.uptimeMillis();

        if (mMoviestart == 0) { 
            mMoviestart = now;

        final int relTime = (int)((now - mMoviestart) % mMovie.duration());
        mMovie.draw(canvas, 10, 10);

BECAUSE OF THE EXCEPTION, movie.duration becomes 0 causing the error.

Any suggestions?

Thank you in advance

You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
For more options, visit this group at
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment