视频播放器截取封面,解决暂停后台黑屏

场景:视频播放器暂停后,后台运行,再次唤起画面黑屏了。

解决方案:

方案一、唤起播放器时候自动播放,来解决。(本文不采取这种方案)

方案二、播放器截屏。

1、已ijk播放器为例,需要设置为TextureRenderView,自带截屏功能,SurfaceRenderView没有这个功能。

/**
 * 视频截屏,播放器提供
 * @return bitmap
 */
public Bitmap getShortcut() {
    return this.mRenderView instanceof TextureRenderView ? ((TextureRenderView) this.mRenderView).getBitmap() : null;
}

已知bug:视频画面较小的时候,封面强行撑满会突然变大。

2、view直接截图进行获取,this就是指的VideoView控件,同样需要设置为TextureRenderView

/**
 * VideoView直接截屏
 * @return bitmap
 */
public Bitmap getCapture() {
    //启用View的DrawingCache功能
    this.buildDrawingCache(true);
    this.setDrawingCacheBackgroundColor(Color.BLACK);
    this.setDrawingCacheEnabled(true);
    this.setVerticalScrollBarEnabled(false);
    this.buildDrawingCache();
    Bitmap bitmap = Bitmap.createBitmap(this.getMeasuredWidth(),    this.getMeasuredHeight(), Bitmap.Config.RGB_565);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    canvas.drawBitmap(bitmap, 0, this.getMeasuredHeight(), paint);
    this.draw(canvas);
    this.destroyDrawingCache(); // 保存过后释放资源
    return bitmap;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值