[英]How to create thumbnail of video url form server
How to create image/thumbnails of url video form server 如何创建URL视频表单服务器的图像/缩略图
and I try is not work (not show thumbnails) 我尝试不起作用(不显示缩略图)
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 !
我被answer1弄糊涂了!
but it get some problem about thumbnails ,it's change color is stange. 但它有一些关于缩略图的问题,它的颜色变了。
example 例
Try this Create new AsyncTask
like this 试试这个创建新的
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);
}
}
Than call this AsyncTask
like this 比这样称呼这个
AsyncTask
new DownloadImage(YourImageView).execute("Your URL");
EDIT 编辑
Or you can also use Glide
to create thumbnail of video from url 或者,您也可以使用
Glide
从url创建视频缩略图
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);
inner class LoadVideoThumbnail : AsyncTask<String, Any, Bitmap>() {
override fun doInBackground(vararg objectURL: String): Bitmap {
//return ThumbnailUtils.createVideoThumbnail(objectURL[0], Thumbnails.MINI_KIND);
val m = MediaMetadataRetriever()
m.setDataSource(objectURL[0], HashMap<String, String>())
var bm = m.getFrameAtTime(-1)
var decoded: Bitmap? = null
if (bm != null) {
val stream = ByteArrayOutputStream()
bm.compress(Bitmap.CompressFormat.PNG, 20, stream)
decoded = BitmapFactory.decodeStream(ByteArrayInputStream(stream.toByteArray()))
}
return decoded!!
}
override fun onPostExecute(result: Bitmap) {
//img.setImageBitmap(result);
Glide.with(this@EditItemsBaseActivity).
load(result)
.listener(object:RequestListener<Bitmap, GlideDrawable> {
override fun onException(e: java.lang.Exception?, model: Bitmap?,
target: Target<GlideDrawable>?, isFirstResource: Boolean): Boolean {
progresBar!!.visibility = View.GONE
return false
}
override fun onResourceReady(resource: GlideDrawable?, model: Bitmap?, target: Target<GlideDrawable>?, isFromMemoryCache: Boolean, isFirstResource: Boolean): Boolean {
progresBar!!.visibility = View.GONE
return false
}
}).
into(videoImageView)
}
}
LoadVideoThumbnail().execute(videoUrl) LoadVideoThumbnail()。execute(videoUrl)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.