2017-12-18 35 views
-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); 
     } 
    } 
+2

的可能的複製[如何創建視頻的URL格式服務器的縮略圖(https://stackoverflow.com/questions/ 44943575 /如何創建thumbnail-of-video-url-form-server) –

+2

可能有[如何顯示視頻縮略圖? Android](https://stackoverflow.com/questions/31646361/how-to-display-a-thumbnail-for-a-video-android) – vinS

+0

**不推薦使用BitmapDrawable **,像這樣使用它'BitmapDrawable bitmapDrawable = BitmapDrawable(context.getResources(),thumb);' –

回答

-1

所有與網絡相關的任務必須是在一個單獨的線程中完成。你不能在主線程中完成它。您可以使用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);