load local mp4 file's thumbnail decode error when filename contain chinese
what should I do? I load mp4's thumbnail using imageloader,anything is normal. But, when I load local mp4 file that contain chinese name,that error come up.
error: E/ImageLoader: Image can't be decoded [file:///storage/emulated/0/easyVR/media/video/你好.mp4_651x311]
finally,i find out why
the problem is this method(BaseImageDownloader) always return false when the name contains chinese
i fixed it
create new class extends BaseImageDownloader, and write this method's imp, just like this

not only video thumbnail, if file path contain chinese character ,decode bitmap will also failure ,so according to this snippet (see follow)
简单来说,如果不想修改库里面的代码,所有中文路径全部通过 content:// 方式(而不是 file://)
的方式 传入 ImageLoader.getInstance().displayImage(uri, imageView, options)
/**
* 获取 路径(文件名)带有中文的 多媒体资源(当前仅限 图片 和 视频) uri
*
* @param context
* @param filePath
* @return filePath 所指向的文件非 图片格式 or 视频格式 返回 null
*/
public static Uri getMediaContentUriCh(Context context, String filePath) {
String extension = "";
//中文路径 因为 MimeTypeMap.getFileExtensionFromUrl(...) 返回null 所以采取 字符串分割方式获取
int i = filePath.lastIndexOf('.');
if (i > 0) {
extension = filePath.substring(i + 1);
}
String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(
extension);
if (mime.startsWith("video/")) {
Cursor cursor = context.getContentResolver().query(
MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
new String[] { MediaStore.Video.Media._ID },
MediaStore.Video.Media.DATA + "=? ",
new String[] { filePath }, null);
if (cursor != null && cursor.moveToFirst()) {
int id = cursor.getInt(cursor
.getColumnIndex(MediaStore.MediaColumns._ID));
cursor.close();
return Uri.withAppendedPath(
MediaStore.Video.Media.EXTERNAL_CONTENT_URI, "" + id);
} else {
if (new File(filePath).exists()) {
ContentValues values = new ContentValues();
values.put(MediaStore.Video.Media.DATA, filePath);
return context
.getContentResolver()
.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
values);
} else {
return null;
}
}
} else if (mime.startsWith("image/")) {
Cursor cursor = context.getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
new String[] { MediaStore.Images.Media._ID },
MediaStore.Images.Media.DATA + "=? ",
new String[] { filePath }, null);
if (cursor != null && cursor.moveToFirst()) {
int id = cursor.getInt(cursor
.getColumnIndex(MediaStore.MediaColumns._ID));
cursor.close();
return Uri.withAppendedPath(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "" + id);
} else {
if (new File(filePath).exists()) {
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.DATA, filePath);
return context.getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
values);
} else {
return null;
}
}
} else {
return null;
}
}