TextureView与MediaPlayer播放视频

TextureView是在API 14引入的,与SurfaceView不同,它不创建新窗口显示内容,而是直接将内容流投放到View中。适用于硬件加速的窗口。SurfaceTexture用于捕获视频流中的图像帧,TextureView可以通过getSurfaceTexture获取SurfaceTexture,实现视频播放。在实现中,需要创建TextureView对象并实现SurfaceTextureListener接口。
摘要由CSDN通过智能技术生成

什么是TextureView

TextureView 是在 4.0(API level 14) 引入的,与 SurfaceView 相比,它不会创建新的窗口来显示内容。它是将内容流直接投放到 View 中,并且可以和其它普通 View 一样进行移动,旋转,缩放,动画等变化。TextureView 必须在硬件加速的窗口中使用。现在的移动设备基本都有GPU进行硬件加速渲染。

SurfaceTexture

在这篇文章中,我们已经知道了 Surface 是内存中一段绘图缓冲区
那么 SurfaceTexture 是什么呢?
SurfaceTexture 用来捕获视频流中的图像帧,视频流可以是相机预览或者是视频解码数据。
TextureView 可以通过 getSurfaceTexture() 方法来获取 TextureView 相应的 SurfaceTexture。

因此我们使用 TextureView 时,首先要获取到用于渲染内容的 SurfaceTexture 。具体做法是先创建 TextureView 对象,然后实现 SurfaceTextureListener 接口

protected void onCreate(Bundle savedInstanceState) {
    setContentView(R.main_layout);
    myTexture = new TextureView(this);
    myTexture.setSurfaceTextureListener(this);
}

Activity implements了SurfaceTextureListener接口因此activity中需要重写如下方法:

@Override
public void onSu
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值