在给定位置的ImageView中生成视频的缩略图

问题描述 投票:0回答:1

下面的代码运行良好,它生成图像来自给定网址的视频缩略图,但我想知道,是否有可能在假设100毫秒生成视频缩略图,因为默认情况下它生成缩略图在开始位置,所以如果在开始视频屏幕是黑色的,然后缩略图也显示黑色,所以它看起来很奇怪。那么有没有可能通过跳过几毫秒来获得缩略图。

public class DownloadImage extends AsyncTask<String, Void, Bitmap> {
        ImageView bmImage;
        String path;

        public DownloadImage(ImageView bmImage, String path) {
            this.bmImage = (ImageView ) bmImage;
            this.path=path;
        }

        protected Bitmap doInBackground(String... urls) {
            Bitmap myBitmap = null;
            MediaMetadataRetriever mMRetriever = null;
            try {
                mMRetriever = new MediaMetadataRetriever();
                if (Build.VERSION.SDK_INT >= 14)
                    mMRetriever.setDataSource(path, new HashMap<String, String>());
                else
                    mMRetriever.setDataSource(path);
                myBitmap = mMRetriever.getFrameAtTime();
            } catch (Exception e) {
                e.printStackTrace();


            } finally {
                if (mMRetriever != null) {
                    mMRetriever.release();
                }
            }
            return myBitmap;
        }

        protected void onPostExecute(Bitmap result) {
            bmImage.setImageBitmap(result);
        }
    }
java android android-videoview android-video-player video-thumbnails
1个回答
0
投票

您可以使用MediaMetadataRetriever的其他重载方法来获取特定时间的帧。

public Bitmap getFrameAtTime(long timeUs, int option) {
    throw new RuntimeException("Stub!");
}

public Bitmap getFrameAtTime(long timeUs) {
    throw new RuntimeException("Stub!");
}

public Bitmap getFrameAtTime() {
    throw new RuntimeException("Stub!");
}
© www.soinside.com 2019 - 2024. All rights reserved.