VideoView getDrawingCache is returning black

后端 未结 2 1234
花落未央
花落未央 2020-11-27 06:39

So I\'m trying to do a screen shot of a VideoView. I figured the easiest way would be:

videoView.setDrawingCacheEnabled(true);

Then when I

2条回答
  •  清酒与你
    2020-11-27 07:32

    Since API 10, you can use MediaMetadataRetriever to retrieve a frame at given time (in micro seconds). Here is a sample code:

    public Bitmap videoFrame(String uri, long msec) {       
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
        try {                       
            retriever.setDataSource(uri);            
            return retriever.getFrameAtTime(msec);
        } catch (IllegalArgumentException ex) {
            ex.printStackTrace();
        } catch (RuntimeException ex) {
            ex.printStackTrace();
        } finally {
            try {
                retriever.release();
            } catch (RuntimeException ex) {
            }
        }
        return null;
    }
    

提交回复
热议问题