0

Currently attempting to get a thumbnail from a returned video (either from gallery or from the video intent on the device) to display in an ImageView, but am getting FileNotFound exceptions and a null Bitmap being returned. Not entirely sure where I'm going wrong although judging by the error it must be the path that is not right somehow. Any ideas?

if (requestCode == GALLERY_VIDEO_CODE  || requestCode == VIDEO_CODE) {
            videoURI = data.getData();
            if(videoURI != null) {
                MediaPlayer mp = MediaPlayer.create(this, videoURI);
                int duration = mp.getDuration();
                mp.release();
                if (duration <= 11000) {
                    addBtn.setVisibility(View.INVISIBLE);
                    clearBtn.setVisibility(View.VISIBLE);
                    Toast.makeText(this, "Video added!", Toast.LENGTH_LONG).show();
                    File file = new File(videoURI.getPath());
                    Bitmap bm = ThumbnailUtils.createVideoThumbnail(file.getAbsolutePath(), MediaStore.Video.Thumbnails.MINI_KIND);
                    userPhoto.setImageBitmap(bm);
                } else {
                    videoURI = null;
                    Toast.makeText(this, "Video too long - maximum duration is 10 seconds", Toast.LENGTH_LONG).show();
                    addBtn.setVisibility(View.VISIBLE);
                    clearBtn.setVisibility(View.INVISIBLE);
                }
markeh21
  • 189
  • 12
  • `File file = new File(videoURI.getPath())` -- this only works if the `Uri` has a `file` scheme. Most of the time, you will not have a `Uri` with a `file` scheme. Instead, it will have a `content` scheme. – CommonsWare Aug 24 '16 at 20:23
  • In which case, is there any way I can get a thumbnail for it? – markeh21 Aug 24 '16 at 20:23
  • Pass `videoURI` to Picasso and let it get you a thumbnail: https://github.com/commonsguy/cw-omnibus/blob/v7.6/RecyclerView/VideoList/app/src/main/java/com/commonsware/android/recyclerview/videolist/RowController.java#L61-L65 – CommonsWare Aug 24 '16 at 20:24
  • Having issues again, doesn't seem to be loading anything into the imageview - have tried both videoURI and videoURI.toString as suggested in the code you linked. Beginning to think I'm just cursed! – markeh21 Aug 24 '16 at 20:30

1 Answers1

1

Somewhat solved this by getting my filepath to put into the createVideoThumbnail() method using this: https://stackoverflow.com/a/20470572/5325511

Community
  • 1
  • 1
markeh21
  • 189
  • 12