Play.gif imagem no android sem usar webview
Eu tentei assim, que eu encontrei na net para jogar imagens gif:
private class MYGIFView extends View {
Movie movie;
InputStream is = null;
long moviestart;
public MYGIFView(Context context) {
super(context);
// Provide your own gif animation file
is = context.getResources().openRawResource(R.drawable.mygif);
movie = Movie.decodeStream(is);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.WHITE);
super.onDraw(canvas);
long now = android.os.SystemClock.uptimeMillis();
System.out.println("now=" + now);
if (moviestart == 0) { // first time
moviestart = now;
}
System.out.println("\tmoviestart=" + moviestart);
int relTime = (int) ((now - moviestart) % movie.duration());
System.out.println("time=" + relTime + "\treltime="
+ movie.duration());
movie.setTime(relTime);
movie.draw(canvas, this.getWidth() / 2 - 20,
this.getHeight() / 2 - 40);
this.invalidate();
}
Embora muitos tenham dito que obtiveram o resultado desejado.
Eu coloquei a imagem gif em drawable. Eu estou recebendo movie.duration () null.
Por favor, sugira onde estou errado ou se há alguma maneira.