Android VideoView黑屏处理

AndroidVideoView大约 1075 字
final VideoView videoView = findViewById(R.id.video_view);
MediaController mc = new MediaController(this);
videoView.setMediaController(mc);
Uri uri = Uri.parse(PATH);
videoView.setVideoURI(uri);

videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer mp) {
        mp.setOnInfoListener(new MediaPlayer.OnInfoListener() {
            @Override
            public boolean onInfo(MediaPlayer mp, int what, int extra) {
                if (what == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START) {
                    videoView.setBackgroundColor(Color.TRANSPARENT);
                }
                return true;
            }
        });
    }
});

MediaMetadataRetriever media = new MediaMetadataRetriever();
media.setDataSource(PATH, new HashMap<String, String>());

//Bitmap bitmap = media.getFrameAtTime();//关键帧
Bitmap bitmap = media.getFrameAtTime(0);//第一帧

//videoView.setBackgroundColor(Color.WHITE);
videoView.setBackground(new BitmapDrawable(Resources.getSystem(), bitmap));

videoView.start();
阅读 1451 · 发布于 2019-04-11

————        END        ————

扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看换一批