...
final int relTime = (int)((now - mMoviestart) % mMovie.duration());
if (relTime >= mMovie.duration()) {
relTime = 0;
}
mMovie.setTime(relTime);
this will start the gif from the beginning!
Вопрос
i want to play a gif file. i am able to show the gif using a movie and drawing a canvas (code below ) . but usually the gifs file comes with an attribute that tells u the number of loop needed. How can i extract that value and show the last frame of the movie ? below is the code i use to play gif :
public TutorialGifView(Context context , InputStream is , int width , int height ) {
super(context);
mContext = context;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
this.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
ScreenWidth = width;
ScreenHeight = height ;
mMovie = Movie.decodeStream(is);
if(ScreenWidth > ScreenHeight)
{
scaleh = (float)height/(float)(mMovie.height()+1);
scalew = ((float)(4*height))/((float)(mMovie.width()*3));
}
else
{
scalew = ((float)width/((float)mMovie.width()+1));
scaleh = ((float)(4*mMovie.width())/(float)(3*mMovie.width()));
}
}
protected void onDraw(Canvas canvas)
{
if (mMovie == null) {
return;
}
canvas.scale(scalew, scaleh);
canvas.drawColor(Color.TRANSPARENT);
super.onDraw(canvas);
final long now = SystemClock.uptimeMillis();
if (mMoviestart == 0) {
mMoviestart = now;
}
final int relTime = (int)((now - mMoviestart) % mMovie.duration());
mMovie.setTime(relTime);
mMovie.draw(canvas, padLeft/scalew , padTop/scaleh);//padLeft/scaleh);
// here i shoud get the loop count
if(LoopCount > 0 )
{
if((now- mMoviestart) > mMovie.duration()*(LoopCount) )
{
setWillNotDraw(true);
return ;
}
}
this.invalidate();
}
Решение
...
final int relTime = (int)((now - mMoviestart) % mMovie.duration());
if (relTime >= mMovie.duration()) {
relTime = 0;
}
mMovie.setTime(relTime);
this will start the gif from the beginning!