如何在Android中获取视频的缩略图 [英] How do I get thumbnail of a video in android

查看:1926
本文介绍了如何在Android中获取视频的缩略图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助来创建从我的android手机录制的视频的缩略图,我从此

I want some help in creating thumbnail of a video being recorded from my android phone and I got this code from this Link, and I modified this part of the code to generate the thumbnail but somehow the thumbnail is not being generated, so any help will be appreciated.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == RESULT_OK && requestCode == VIDEO_CAPTURED) {
        videoFileUri = data.getData();
        if (videoFileUri != null) {
           Bitmap image= ThumbnailUtils.createVideoThumbnail(videoFileUri.toString(),MODE_APPEND);

 ImageView imageView=(ImageView)findViewById(R.id.image);
 imageView.setImageBitmap(image);
        }

        playVideoButton.setEnabled(true);
    }
}

推荐答案

您可以使用glide.其自动设置的视频缩略图.

You can use glide. its automatically set thumb image of video.

Glide还可以显示视频的缩略图,只要它们存储在手机中即可.让我们假设您通过让用户选择视频来获取文件路径:基于此文档 https://futurestud.io/tutorials/glide-displaying-gifs-and-视频

Glide is also able to display the thumbnail of videos, as long as they're stored on the phone. Let's assume you get the file path by letting the user select a video: Based on this document https://futurestud.io/tutorials/glide-displaying-gifs-and-videos

String filePath = "/storage/emulated/0/Pictures/example_video.mp4";

Glide  
    .with(context)
    .asBitmap()
    .load(Uri.fromFile(new File(filePath)))
    .into(imageViewGifAsBitmap);

这篇关于如何在Android中获取视频的缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆