0

I have implemented Gif movie player using https://github.com/sbakhtiarov/gif-movie-view, it's working good but I want pause Gif image when first start activity, that means first open activity, I tried gif1.setPaused(true); but it's not working so how can i solve it? Please guys help to solve it!!!

2 Answers2

1

I solve it using onDraw method, Just change

@Override
    protected void onDraw(Canvas canvas) {
        //for infinitive time animate
        /*if (mMovie != null) {
            if (!mPaused) {
                updateAnimationTime();
                drawMovieFrame(canvas);
                invalidateView();
            } else {
                drawMovieFrame(canvas);
            }
        }*/

        //for one time animate
        final long now = SystemClock.uptimeMillis();
        if (mMovieStart == 0) {
            mMovieStart = (int) now;
        }

        if (mMovie != null) {
            if (!mPaused) {
                int relTime = (int) (now - mMovieStart);

                if (relTime > mMovie.duration()) {
                    relTime = mMovie.duration();
                }

                mMovie.setTime(relTime);
                mMovie.draw(canvas,
                        getWidth() / 2 - mMovie.width() / 2,
                        getHeight() / 2 - mMovie.height() / 2);

                if (relTime < mMovie.duration()) {
                    invalidate();
                }
            } else {
                drawMovieFrame(canvas);
            }
        }
    }

And put in MainActivity

 gif1.setMovieResource(R.drawable.earth_tilt_animation);
        gif1.setPaused(!gif1.isPaused());
0

Try this

gif.setPaused(!gif.isPaused());

Because there is no code in library for gif1.setPaused(true);

Just check in GifMovieView.java

public void setPaused(boolean paused) {
    this.mPaused = paused;

    /**
     * Calculate new movie start time, so that it resumes from the same
     * frame.
     */
    if (!paused) {
        mMovieStart = android.os.SystemClock.uptimeMillis() - mCurrentAnimationTime;
    }

    invalidate();
}

Try to make one function in GifMovieView.java

public void stop() {    
    mMovie.stop;
    invalidate();
}

I m not sure it works but hope it will work.

Chirag Ghori
  • 4,231
  • 2
  • 20
  • 35