从图库中查看缩略图(file:///)Android

时间:2019-01-02 21:37:40

标签: android bitmap

我有路径:file:///storage/emulated/0/Download/video38_b2449d069604693e162fbda8b7d5b9a4.mp4,我想从该路径显示缩略图。我尝试了许多不同的小工具,但无济于事,无法解决我的问题。

String path = file:///storage/emulated/0/Download/video38_b2449d069604693e162fbda8b7d5b9a4.mp4

不起作用

 Bitmap thumb = ThumbnailUtils.createVideoThumbnail(path ,
            MediaStore.Images.Thumbnails.MINI_KIND);

输出:

thumb  == null

不起作用

public static Bitmap retriveVideoFrameFromVideo(String videoPath)
            throws Throwable {
        Bitmap bitmap = null;
        MediaMetadataRetriever mediaMetadataRetriever = null;
        try {
            mediaMetadataRetriever = new MediaMetadataRetriever();
            if (Build.VERSION.SDK_INT >= 14)
                mediaMetadataRetriever.setDataSource(videoPath, new HashMap<String, String>()); // this line error
            else
                mediaMetadataRetriever.setDataSource(videoPath);

            bitmap = mediaMetadataRetriever.getFrameAtTime(1, MediaMetadataRetriever.OPTION_CLOSEST);
        } catch (Exception e) {
            e.printStackTrace();
            throw new Throwable(
                    "Exception in retriveVideoFrameFromVideo(String videoPath)"
                            + e.getMessage());

        } finally {
            if (mediaMetadataRetriever != null) {
                mediaMetadataRetriever.release();
            }
        }
        return bitmap;
    }

0 个答案:

没有答案