-3

Need to generate thumbnail from video stored in server, below is my code but "path" variable is giving problem, how to get it resolved. If i remove path parameter with url parameter then i am getting the thumbnails but not in proper order or sometimes same thumbnail is generated for 2 or 3 videos, below is my code -

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);
        }
    }
Nayan Das
  • 75
  • 7
  • 2
    Possible duplicate of [How to create thumbnail of video url form server](https://stackoverflow.com/questions/44943575/how-to-create-thumbnail-of-video-url-form-server) – AskNilesh Dec 18 '17 at 09:53
  • 2
    Possible duplicate of [How to display a thumbnail for a video? Android](https://stackoverflow.com/questions/31646361/how-to-display-a-thumbnail-for-a-video-android) – vinS Dec 18 '17 at 09:53
  • **BitmapDrawable is not deprecated**, use it like this `BitmapDrawable bitmapDrawable = BitmapDrawable(context.getResources(), thumb);` – Abhishek Singh Dec 18 '17 at 09:53
  • **ThumbnailUtils.createVideoThumbnail()** works for local path only. Use the link above posted by Nilu. – ADM Dec 18 '17 at 09:55

1 Answers1

-1

All the network related task must be done in a separate thread. You can't do it in main thread. You can use Picasso image library. It is open source and you can show different image for different state like loading, error etc.

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