我在girdview中使用通用图像加载器。有些视频可以改变图像,有些不起作用,并且会出现错误,
03-17 12:49:52.287: D/skia(21755): --- SkImageDecoder::Factory returned null
03-17 12:49:52.287: E/ImageLoader(21755): Image can't be decoded [file:////storage/sdcard0/Movies/Naruto Episodes 55.mp4_270x270]
这是我在主类中的代码。
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
.cacheOnDisc(true).cacheInMemory(true)
.imageScaleType(ImageScaleType.EXACTLY)
.displayer(new FadeInBitmapDisplayer(300)).build();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
getApplicationContext())
.defaultDisplayImageOptions(defaultOptions)
.memoryCache(new WeakMemoryCache())
.discCacheSize(100 * 1024 * 1024).build();
ImageLoader.getInstance().init(config);
以下是adpater中的代码,
String url = "/storage/sdcard0/Movies/Naruto Episodes 55.mp4";
ImageLoader imageLoader = ImageLoader.getInstance();
DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory(true)
.cacheOnDisc(true).resetViewBeforeLoading(true)
.showImageForEmptyUri(R.drawable.x_document_icon)
.showImageOnFail(R.drawable.x_document_icon)
.showImageOnLoading(R.drawable.x_document_icon).build();
//initialize image view
//download and display image from url
imageLoader.displayImage("file:///"+url, img_btn, options);
以下代码工作正常,但需要一些时间。
Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(url, 0);
img_btn.setImageBitmap(bitmap);
答案 0 :(得分:0)
您的文件名包含Github中有issue posted的空格。根据评论,这个解决方案有效但我还没有尝试过:
if (file.exists()) {
final String uri = Uri.fromFile(file).toString();
final String decoded = Uri.decode(uri);
ImageLoader.getInstance().displayImage(decoded, imageView);
}
根据你的评论,这应该有效:
String url = "/storage/sdcard0/Movies/Naruto Episodes 55.mp4";
imageLoader.displayImage("file:///"+Uri.decode(url), img_btn, options);