-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);' –