java – 如何创建视频url表单服务器的缩略图
作者:互联网
如何创建url视频表单服务器的图像/缩略图
我尝试不工作(不显示缩略图)
String String url = "http://clips.vorwaerts-gmbh.de/VfE_html5.mp4";
Bitmap thumb = ThumbnailUtils.createVideoThumbnail(url,MediaStore.Images.Thumbnails.MINI_KIND);
Glide.with(context).load(thumb).asBitmap()
/*.override(convertDpToPx(100), convertDpToPx(100))*/
.placeholder(R.drawable.camera)
.override(200, 200)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(new BitmapImageViewTarget(img_view) {
protected void setResource(Bitmap resource) {
RoundedBitmapDrawable circularBitmapDrawable =
RoundedBitmapDrawableFactory.create(context.getResources(), resource);
//circularBitmapDrawable.setCircular(true);
img_view.setImageDrawable(circularBitmapDrawable);
}
});
I get slove it by answer1 !
但是它在缩略图方面遇到了一些问题,它的变化颜色就是标准.
例
解决方法:
试试这个创建新的AsyncTask
public class DownloadImage extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImage(ImageView bmImage) {
this.bmImage = (ImageView ) bmImage;
}
protected Bitmap doInBackground(String... urls) {
Bitmap myBitmap = null;
MediaMetadataRetriever mMRetriever = null;
try {
mMRetriever = new MediaMetadataRetriever();
if (Build.VERSION.SDK_INT >= 14)
mMRetriever.setDataSource(urls[0], new HashMap<String, String>());
else
mMRetriever.setDataSource(urls[0]);
myBitmap = mMRetriever.getFrameAtTime();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (mMRetriever != null) {
mMRetriever.release();
}
}
return myBitmap;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
比调用这个AsyncTask
new DownloadImage(YourImageView).execute("Your URL");
编辑
或者您也可以使用Glide
从网址创建视频缩略图
RequestOptions requestOptions = new RequestOptions();
requestOptions.placeholder(R.drawable.placeholder_card_view);
requestOptions.error(R.drawable.placeholder_card_view);
Glide.with(getContext())
.load(path)
.apply(requestOptions)
.thumbnail(Glide.with(getContext()).load(path))
.into(ivVideoThumbnail);
标签:android,java,video,thumbnails 来源: https://codeday.me/bug/20190918/1811307.html