[英]thumbnail video from url using image?
I already success display thumbnail video from URL on my android app when internet connection is connected, but when internet connection is off the thumbnail doesn't display. 连接互联网连接后,我已经成功在Android应用程序上显示了来自URL的缩略图视频,但是当互联网连接关闭时,缩略图不显示。
here is my code. 这是我的代码。
Bitmap bmThumbnail;
bmThumbnail = ThumbnailUtils.createVideoThumbnail("http://somedomain.com/video/myvideo.mp4", Thumbnails.MICRO_KIND );
imgPhoto.setImageBitmap(bmThumbnail);
i want the thumbnail still display although connection is off,there is away to achieve like save the cache on sdcard
first, like image cache does? 我想在连接断开的情况下仍然显示缩略图,还有没有办法像先将缓存保存在
sdcard
一样,就像图像缓存一样? or any other solution to show thumbnail video when internet connection is off? 或其他任何解决方案,可以在互联网连接关闭时显示缩略图视频? thanks,
谢谢,
public static String getBitmapFromURL(final Activity activity, String link,
String filename) throws FileNotFoundException,
MalformedURLException, IOException {
/*--- this method downloads an Image from the given URL,
* then decodes and returns a Bitmap object
---*/
File file = null;
file = new File(Environment.getExternalStorageDirectory()
.getAbsolutePath()
+ CommonVariable.KCS_IMAGE_FOLDER_NAME_PHONE_MEMORY);
// have the object build the directory structure, if needed.
if (!file.exists()) {
file.mkdirs();
}
// create a File object for the output file
File outputFile = new File(file, filename);
FileOutputStream fos = new FileOutputStream(outputFile);
BufferedOutputStream out = new BufferedOutputStream(fos, 1024);
URL url = new URL(link);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
out = new BufferedOutputStream(fos, 1024);
int b;
while ((b = input.read()) != -1) {
out.write(b);
}
out.close();
connection.disconnect();
return outputFile.getAbsolutePath();
}
use this function,it will return string of sdcard path.and use this path u can set bitmap image using below function: 使用此功能,将返回SD卡路径的字符串。使用此路径,您可以使用以下功能设置位图图像:
public static void setImagesNew(ImageView img, String pathName,
Activity activity) {
Bitmap bmThumbnail = ThumbnailUtils.createVideoThumbnail(pathName, Thumbnails.MICRO_KIND );
img.setImageBitmap(bmThumbnail);
bmp = null;
System.gc();
Runtime.getRuntime().gc();
}
i hope this is useful to you............... 我希望这对您有用...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.