gif动画加载遇到的问题

1.https://github.com/koral--/android-gif-drawable
优秀的库。GifDrawable可以添加动画监听,监听播放完成。
可以添加MediaController监听。
遇到的问题:在乐视电视上,公司的app,内部集成了flash的播放器。player和这个库冲突。没办法,只能换。
2.glide加载gif图,也能监听播放完成。
下载:glide-3.6.0.jar。

public class LoadingActivity extends BaseActivity {
    private ImageView gifView;
    private int duration;
    public static final int MSG_COMPLETE=1;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_loading);

        gifView = (ImageView) findViewById(R.id.gifView);
        Glide.with(this)
                .load(R.drawable.logo_gif)
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .listener(new RequestListener() {

                    @Override
                    public boolean onException(Exception arg0, Integer arg1,
                                               Target arg2, boolean arg3) {
                        return false;
                    }

                    @Override
                    public boolean onResourceReady(GlideDrawable resource,
                                                   Integer model, Target target,
                                                   boolean isFromMemoryCache, boolean isFirstResource) {
                        // 计算动画时长
                        GifDrawable drawable = (GifDrawable) resource;
                        GifDecoder decoder = drawable.getDecoder();
                        for (int i = 0; i < drawable.getFrameCount(); i++) {
                            duration += decoder.getDelay(i);
                        }
                        //发送延时消息,通知动画结束
                        handler.sendEmptyMessageDelayed(MSG_COMPLETE,
                                duration);
                        return false;
                    }
                }) //仅仅加载一次gif动画
                .into(new GlideDrawableImageViewTarget(gifView, 1));

    }

    @Override
    protected void leaveActivity() {

    }
    private Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if(msg.what==MSG_COMPLETE){
                Intent intent = new Intent(LoadingActivity.this, HomeActivity.class);
                startActivity(intent);
                finish();
            }
        }
    };
}

你可能感兴趣的:(gif动画加载遇到的问题)