视频以GIF样式在列表中加载

先看效果

6049BAFC9317BE48A6B7BF12C7382730.gif

实现起来很简单,就是获取视频的前50帧,然后循环展示
代码如下

以七牛云存储为例

                mBitmaps = new Bitmap[50];
                for (int i = 0; i < 50; i++) {
                    final int finalI = i;
                    final String url = videoUrl + "?vframe/jpg/offset/" + (i + 1)/10f;
                    mHandler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            if(((Activity)getContext()).isFinishing()){
                                return;
                            }
                            Glide.with(getContext()).load(url).into(new SimpleTarget() {
                                @Override
                                public void onResourceReady(GlideDrawable resource, GlideAnimation glideAnimation) {
                                    if (resource instanceof GlideBitmapDrawable) {
                                        GlideBitmapDrawable gifDrawable = (GlideBitmapDrawable) resource;
                                        Bitmap bitmap = gifDrawable.getBitmap();
                                        if(bitmap != null){
                                            mBitmaps[finalI] = bitmap;
                                        }
                                        Logs.i("final:::" + finalI);
                                        if (finalI == 3) {
                                            info.setBitmaps(mBitmaps);
                                            startCirclePlay();
                                        }

                                    }
                                }

                                @Override
                                public void onLoadFailed(Exception e, Drawable errorDrawable) {
                                    super.onLoadFailed(e, errorDrawable);
                                    startCirclePlay();
                                }
                            });

                        }
                    }, 100 * i);

                }

你可能感兴趣的:(视频以GIF样式在列表中加载)