android 获取视频缩略图

使用接口类 MediaMetadataRetriever 获取视频缩略图

    public Bitmap getVideoThumbnail(String filePath) {  
    Bitmap bitmap = null;  
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();  
    try {  
        retriever.setDataSource(filePath);  
        bitmap = retriever.getFrameAtTime();  
    }   
    catch(IllegalArgumentException e) {  
        e.printStackTrace();  
    }   
    catch (RuntimeException e) {  
        e.printStackTrace();  
    }   
    finally {  
        try {  
            retriever.release();  
        }   
        catch (RuntimeException e) {  
            e.printStackTrace();  
        }  
    }  
    return bitmap;  
}  

其中函数getFrameAtTime()有其他重载函数,该函数会随机选择一帧抓取,如果想要指定具体时间的缩略图,可以用函数getFrameAtTime(long timeUs), getFrameAtTime(long timeUs, int option),具体如何使用可以查doc。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容