5

嗨,我是韩国的开发人员。我有一些问题,所以我进入了这个网站。

    InputStream is;
    URL url = 
         new URL("http://112.216.25.58:8888/VOD_LAUNCHER/media/youtube_sample3.mp4");
    Uri uri = Uri.parse(url.toURI().toString());
    is = getContentResolver().openInputStream(uri);
    Bitmap bitmap = BitmapFactory.decodeStream(is);
    //Bitmap bitmap = BitmapFactory.decodeFile(url.toString());
    //MediaMetadataRetriever ret = new MediaMetadataRetriever();
    //ret.setDataSource(url.toString());
    //Bitmap bitmap = ret.getFrameAtTime(0);
    //mImageView.setImageURI(uri);

    //Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(uri.toString(), Thumbnails.MICRO_KIND);
    mImageView.setImageBitmap(bitmap);

private Bitmap getPreview(URI uri) {
        File image = new File(uri);

    BitmapFactory.Options bounds = new BitmapFactory.Options();
    bounds.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(image.getPath(), bounds);
    if ((bounds.outWidth == -1) || (bounds.outHeight == -1))
        return null;

    int originalSize = (bounds.outHeight > bounds.outWidth) ? bounds.outHeight
            : bounds.outWidth;

    BitmapFactory.Options opts = new BitmapFactory.Options();
    //opts.inSampleSize = originalSize / THUMBNAIL_SIZE;
    return BitmapFactory.decodeFile(image.getPath(), opts);     
}

private String getRealPathFromURI(Uri contentUri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    CursorLoader loader = new CursorLoader(getApplicationContext(), 
                                              contentUri, proj, null, null, null);
    Cursor cursor = loader.loadInBackground();
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}

我尝试使用 ThumbnailUtil 等,但它没有用。如何在 android 4.0 上获取 ThumbnailImage?感谢任何回复。

4

4 回答 4

20

从 API 级别 8 开始,您可以这样做:

String path = /*get video path*/;
Bitmap thumb = ThumbnailUtils.createVideoThumbnail(path,
                MediaStore.Images.Thumbnails.MINI_KIND);

很好很简单:)

于 2014-02-17T14:46:56.190 回答
7

如果你想提取视频的一帧,你应该使用这个类。代码应该是这样的:

MediaMetadataRetriever media = new MediaMetadataRetriever();
media.setDataSource(path);
Bitmap extractedImage = media.getFrameAtTime(time, option);

希望有用

于 2013-10-15T15:26:01.300 回答
1

试试这个来获取视频的缩略图。

ImageView videoview;
 Bitmap thumb = ThumbnailUtils.createVideoThumbnail("YOUR VIDEO STRING PATH",   MediaStore.Images.Thumbnails.MINI_KIND);
 Matrix matrix = new Matrix();
 Bitmap bmThumbnail = Bitmap.createBitmap(thumb, 0, 0,
 thumb.getWidth(), thumb.getHeight(), matrix, true);
 videoview.setImageBitmap(bmThumbnail);

编辑:使用此方法获取视频 URI 的字符串路径。

/**
     * Try to return the absolute file path of the Gallery video.
     * 
     * @param context
     * @param uri
     * @return the file path or null
     */
    public static String getVideoPathFromGallary(final Context context,Uri contentUri) {
        String[] proj = {  MediaStore.Video.Media.DATA, MediaStore.Video.Media.SIZE, MediaStore.Video.Media.DURATION};
        Cursor cursor = ((Activity) context).managedQuery(contentUri, proj, null, null, null);
        if (cursor == null)
            return null;
        cursor.moveToFirst();
        int column_index = cursor
                .getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
        int fileSize = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE));
        long duration = TimeUnit.MILLISECONDS.toSeconds(cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION)));
        System.out.println("size: " + fileSize);
        System.out.println("duration: " + duration);
        return cursor.getString(column_index);
    }
于 2013-10-15T06:59:05.543 回答
1

很简单 !!!你可以使用滑翔库。

首先在 videoView 上添加一个 imageView 并使用下面的代码:

>

 GlideApp.with(getApplicationContext()).load("empty")
    .thumbnail(GlideApp.with(getApplicationContext()).load("videoURL"))
    .into(imageView);

此代码将下载图像,并最终导致互联网消耗减少。

于 2020-04-29T06:37:03.397 回答