在gridview上加载视频缩略图非常慢

时间:2019-04-28 07:52:19

标签: java android gridview bitmap thumbnails

使用外部存储目录中的位图创建视频缩略图。加载gridview变得非常缓慢。有什么方法可以使缩略图拍摄变得更快,更容易?


private void populateVideoFiles() {
        String videoReceivedPath = Environment.getExternalStorageDirectory() + "/Media/Video/";
        String videoCache = Environment.getExternalStorageDirectory() + "/Media/Temp/";
        list_VideoPropFiles = new ArrayList();
        File[] allFiles = new File(videoReceivedPath).listFiles();
        for (int i = allFiles.length-1; i >=0 ; i--) {
            if (allFiles[i].isFile()) {
                totalSize += allFiles[i].length();
                numofFiles += 1;
                String cacheFileName = videoCache + allFiles[i].getName() + ".jpeg";
                Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(allFiles[i].toString(), MediaStore.Video.Thumbnails.MINI_KIND);
                if(bitmap != null) {
                    writeExternalToCache(bitmap, cacheFileName);
                } else {
                    Bitmap no_thumbs = BitmapFactory.decodeResource(getActivity().getResources(), R.drawable.nothumbs);
                    writeExternalToCache(no_thumbs, cacheFileName);
                }
                list_VideoPropFiles.add(new VideoProperties(allFiles[i].getAbsolutePath(), cacheFileName, String.valueOf(allFiles[i].length()), false));
            }
        }
    }

0 个答案:

没有答案