Android之获取视频缩略图

/**
 * 获取视频缩略图
 *
 * @param app
 * @param fdir
 * @param fname
 * @return
 */
public Bitmap getVideoThumbnailByExternal(String app, String fdir, String fname) {
    File dir = Environment.getExternalStorageDirectory();
    Log.d("Get Video Thumbnail ->", String.format("%s/%s/%s/%s", dir, app, fdir, fname));
    Bitmap bitmap = null;
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    try {
        retriever.setDataSource(String.format("%s/%s/%s/%s", dir, app, fdir, fname));
        // 可以指定具体时间的缩略图 ...
        bitmap = retriever.getFrameAtTime();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (RuntimeException e) {
        e.printStackTrace();
    } finally {
        try {
            retriever.release();
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
    }
    return bitmap;
}