从视频ANDROID获取缩略图时的FileNotFoundException

时间:2017-07-16 17:21:58

标签: java android video bitmap filenotfoundexception

当我尝试从手机图库视频中获取视频缩略图时,我遇到了问题。我有一个获取视频缩略图位图的方法,但这种方法效果不佳。我的方法的减号是,对于某些视频,它不起作用,我得到了#34; FileNotFoundException"但是对于某些视频,这种方法工作正常。

 private void pickVideosFromGallery() {
    Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(i, SELECTED_VIDEO);
}

 @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != Activity.RESULT_OK){
        return;
    }
    switch (requestCode)
    {
        case SELECTED_VIDEO:
            Uri uri = data.getData();
            String[] projection = {MediaStore.Video.VideoColumns.DATA};

            Cursor cursor = getContext().getContentResolver().query(uri, projection, null, null, null);
            cursor.moveToFirst();

           int columnIndex = cursor.getColumnIndex(projection[0]);
            filePath = cursor.getString(columnIndex);
            cursor.close();

            Bitmap bit = ThumbnailUtils.createVideoThumbnail(filePath, MediaStore.Video.Thumbnails.FULL_SCREEN_KIND);
            break;

}}

07-16 20:11:49.647 32387-32387/com.example.tstv.keepfavoritevideos E/folderFragment: Video Path: android.graphics.Bitmap@71d9de1
07-16 20:12:49.992 32387-32387/com.example.tstv.keepfavoritevideos E/MediaMetadataRetriever: setDataSource - FileNotFoundException
07-16 20:12:49.992 32387-32387/com.example.tstv.keepfavoritevideos E/folderFragment: Video Path: null

正如你从日志中看到的那样,对于某些视频而言,它正在运行,而我正在获取位图,但对于某些它不起作用。为什么?

0 个答案:

没有答案