目前正在尝试从返回的视频中获取缩略图(来自图库或来自设备上的视频目标)以在ImageView中显示,但是我收到FileNotFound异常并返回空位图。不完全确定我哪里出错了,虽然从错误判断它必定是不正确的路径。有什么想法吗?
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);
}
答案 0 :(得分:1)
通过使用以下方法将文件路径放入createVideoThumbnail()方法,解决了这个问题:https://stackoverflow.com/a/20470572/5325511