Tuesday, April 30, 2013

[android-developers] To play gif from a file

Hi,
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");
       
        if(file.exists()){
        
               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 ;

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawColor(Color.TRANSPARENT);
        super.onDraw(canvas);
        final long now = SystemClock.uptimeMillis();

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

        
        Log.i("",""+mMovie.duration());
        
        Log.i("",""+mMoviestart);
        
        final int relTime = (int)((now - mMoviestart) % mMovie.duration());
        mMovie.setTime(relTime);
        mMovie.draw(canvas, 10, 10);
        this.invalidate();
    }


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
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
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