Skip to content

Commit 1b78e3e

Browse files
committed
Update BaseImageDownloader.java
Based on added an schema to support video of sdcard and it will be used to get video thumnail from the sdcard video path i.e. /storage/emulated/0/Video/VID_20141015_184740.mp4 or video of any folder. And to get video thumnail in getView of adapter or for single image we can use it like this way imageLoader.displayImage("video://"+imageVideoPath,holder.ivVideoThumbnail, MyApplication.options, null); where imageVideoPath is String or Video file path i.e. /storage/emulated/0/Video/VID_20141015_184740.mp4
1 parent b9f1006 commit 1b78e3e

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

library/src/com/nostra13/universalimageloader/core/download/BaseImageDownloader.java

+41-2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ public InputStream getStream(String imageUri, Object extra) throws IOException {
9292
return getStreamFromAssets(imageUri, extra);
9393
case DRAWABLE:
9494
return getStreamFromDrawable(imageUri, extra);
95+
case VIDEO:
96+
return getStreamFromSdCardVideo(imageUri, extra);
9597
case UNKNOWN:
9698
default:
9799
return getStreamFromOtherSource(imageUri, extra);
@@ -217,7 +219,29 @@ protected InputStream getStreamFromDrawable(String imageUri, Object extra) {
217219
int drawableId = Integer.parseInt(drawableIdString);
218220
return context.getResources().openRawResource(drawableId);
219221
}
220-
222+
/**
223+
* Retrieves {@link InputStream} of video thumbnail by URI (video is located on the local file system or SD card).
224+
*
225+
* @param imageUri Image URI
226+
* @param extra Auxiliary object which was passed to {@link DisplayImageOptions.Builder#extraForDownloader(Object)
227+
* DisplayImageOptions.extraForDownloader(Object)}; can be null
228+
* @return {@link InputStream} of video thumbnail
229+
* @throws IOException if some I/O error occurs reading from file system
230+
*/
231+
protected InputStream getStreamFromSdCardVideo(String imageUri, Object extra) throws FileNotFoundException {
232+
imageUri=imageUri.replace("video://", "");
233+
Uri uri = Uri.parse(imageUri);
234+
if (isSDCardVideoUri(uri)) { // video thumbnail
235+
Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(imageUri,
236+
MediaStore.Images.Thumbnails.FULL_SCREEN_KIND);
237+
if (bitmap != null) {
238+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
239+
bitmap.compress(CompressFormat.PNG, 0, bos);
240+
return new ByteArrayInputStream(bos.toByteArray());
241+
}
242+
}
243+
return null;
244+
}
221245
/**
222246
* Retrieves {@link InputStream} of image by URI from other source with unsupported scheme. Should be overriden by
223247
* successors to implement image downloading from special sources.<br />
@@ -244,4 +268,19 @@ private boolean isVideoUri(Uri uri) {
244268

245269
return mimeType.startsWith("video/");
246270
}
247-
}
271+
private boolean isSDCardVideoUri(Uri uri) {
272+
String mimeType = getMimeType(uri.toString());
273+
if (mimeType == null) {
274+
return false;
275+
}
276+
277+
return mimeType.startsWith("video/");
278+
}
279+
public static String getMimeType(String url)
280+
{
281+
String extension = url.substring(url.lastIndexOf("."));
282+
String mimeTypeMap = MimeTypeMap.getFileExtensionFromUrl(extension);
283+
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(mimeTypeMap);
284+
return mimeType;
285+
}
286+
}

0 commit comments

Comments
 (0)