Android 獲取網路視訊縮圖
阿新 • • 發佈:2018-12-04
一、
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; } });