-3
需要从存储在服务器中的视频生成缩略图,下面是我的代码,但“路径”变量给出问题,如何解决问题。如果我删除路径参数与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);
}
}
的可能的复制[如何创建视频的URL格式服务器的缩略图(https://stackoverflow.com/questions/ 44943575 /如何创建thumbnail-of-video-url-form-server) –
可能有[如何显示视频缩略图? Android](https://stackoverflow.com/questions/31646361/how-to-display-a-thumbnail-for-a-video-android) – vinS
**不推荐使用BitmapDrawable **,像这样使用它'BitmapDrawable bitmapDrawable = BitmapDrawable(context.getResources(),thumb);' –