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);
}
Somewhat solved this by getting my filepath to put into the createVideoThumbnail() method using this: https://stackoverflow.com/a/20470572/5325511