现在我须要播放网络上下载的GIF,但似乎Movie只能播放本地APP内的Gif文件。
请问有人作过能让MOVIE播放网络GIF的DEMO
先谢了。

解决方案 »

  1.   

    网上有一个开源项目,GifView打开源码,按照自己项目的须要修改。
      

  2.   

    public class GifPlayByMovie {
    private Activity activity;
    private Movie mMovie;
    private long mMovieStart;
    private boolean playing;
        private int x, y;
        private int expessionId;
        private int time;

    public GifPlayByMovie(Activity activity) {
    this.activity = activity;
    }
        
    public void startPlay(int resId, int x, int y, int playtime)
    {
    if (mMovie != null) {
    return;
    }
    this.x=x;
    this.y=y;
    expessionId = resId;
    mMovieStart = 0;
    playing = true;
    time = playtime*1000;
    }

    public void gifplay(Canvas canvas) {
    if (!playing) {
    return;
    }
    mMovie = Movie.decodeStream(activity.getResources().openRawResource(
    expessionId));
    long now = android.os.SystemClock.uptimeMillis(); if (mMovieStart == 0) { // first time
    mMovieStart = now;
    }
    if (mMovie != null) { int dur = mMovie.duration();
    if (dur == 0) {
    dur = 1000;
    }
    int relTime = (int) ((now - mMovieStart) % dur);
    mMovie.setTime(relTime);
    mMovie.draw(canvas, x, y);
    // invalidate();
    }
    long tmp = now - mMovieStart;
    if (tmp > time) {
    mMovie = null;
    //mMovieStart = 0;
    playing = false;
    }
    }
    }这样写播放gif时 有时出现花屏 大家遇到过没有?