【发布时间】:2013-08-21 02:45:29
【问题描述】:
如何获取正在播放的 gif 动画的持续时间?我想要它的持续时间,我正在使用 Movie 类并且动画是一个循环。但是由于 Movie 类,它被一次又一次地播放。我可以知道如何获取单个循环的持续时间吗?
public class GIFView extends View {
private Movie mMovie;
private long movieStart;
public GIFView(Context context) {
super(context);
initializeView();
}
public GIFView(Context context, AttributeSet attrs) {
super(context, attrs);
initializeView();
}
public GIFView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initializeView();
}
private void initializeView() {
InputStream is = getContext().getResources().openRawResource(
R.drawable.imageedit_ball);
mMovie = Movie.decodeStream(is);
}
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.TRANSPARENT);
super.onDraw(canvas);
long now = android.os.SystemClock.uptimeMillis();
if (movieStart == 0) {
movieStart = (int) now;
}
if (mMovie != null) {
int relTime = (int) ((now - movieStart) % mMovie.duration());
mMovie.setTime(relTime);
mMovie.draw(canvas, getWidth() - mMovie.width(), getHeight()
- mMovie.height());
this.invalidate();
}
}}
【问题讨论】:
-
duration() 会重复什么?
-
我什么都猜不到,如何打印持续时间的值?
-
使用 Log.d() 和 adb logcat