来自服务器的视频的缩略图未在ImageView中显示
需要从存储在服务器中的视频生成缩略图,下面是我的代码,但“路径”变量给出问题,如何解决问题。如果我删除路径参数与URL参数,然后我得到了2级或3的视频生成相同的缩略图的缩略图,但没有按照正确的顺序或有时,下面是我的代码 -来自服务器的视频的缩略图未在ImageView中显示
Video video = mVideos.get(position); //play video using android api, when video view is clicked.
url = video.getVideoUrl(); // your URL here
Uri videoUri = Uri.parse(url);
new DownloadImage(holder.videothumbView).execute(url);
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(path, new HashMap<String, String>());
else
mMRetriever.setDataSource(path);
myBitmap = mMRetriever.getFrameAtTime();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (mMRetriever != null) {
mMRetriever.release();
}
}
return myBitmap;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
回答:
所有与网络相关的任务必须是在一个单独的线程中完成。你不能在主线程中完成它。您可以使用Picasso图像库。它是开源的,你可以显示像装载不同的国家不同的图像,差错等
Picasso.with(context) // your activity of other context referance .load(video.getVideoUrl())
.placeholder(R.drawable.user_placeholder) // this will show during image loading from network
.error(R.drawable.user_placeholder_error) // error image to display
.into(holder.videothumbView);
以上是 来自服务器的视频的缩略图未在ImageView中显示 的全部内容, 来源链接: utcz.com/qa/262231.html