1. 程式人生 > >Android 獲取網路視訊縮圖

Android 獲取網路視訊縮圖

一、

private void getNetVideoBitmap(final String videoUrl) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            Bitmap bitmap = null;
            MediaMetadataRetriever retriever = new MediaMetadataRetriever();
            try {
                //根據url獲取縮圖
                retriever.setDataSource(videoUrl, new HashMap());
                //獲得第一幀圖片
                bitmap = retriever.getFrameAtTime();
                Message message=new Message();
                message.what=1;
                Bundle bundle=new Bundle();
                bundle.putParcelable("msg", bitmap);
                message.setData(bundle);
                mHandler.sendMessage(message);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }).start();
}

二、

private Handler mHandler = new Handler(new Handler.Callback() {
    @Override
    public boolean handleMessage(Message msg) {
        if (msg.what==1){
            final Bitmap bitmap = msg.getData().getParcelable("msg");
            videoIv.setImageBitmap(bitmap);
        }
        return false;
    }
});