本文共 1163 字,大约阅读时间需要 3 分钟。
如题,这两个问题其实是同一个问题,为什么这么说呢?因为之前获取SurfaceTexture是在onSurfaceTextureAvailable接口里操作的,既然onSurfaceTextureAvailable没回调,获取的SurfaceTexture为空,自然没画面了。
在我的项目升级targetSdkVersion到29之后就会出现,我并不清楚onSurfaceTextureAvailable接口为什么不会执行,不过改完代码后不妨碍项目正常运行就可以了。
查了资料都说要开启硬件加速:android:hardwareAccelerated="true"
卵用没有。
反正在我的小米手机android 10系统上,完全没有效果。
但是调试发现,除了onSurfaceTextureAvailable这个接口没响应,其他接口是正常的,例如onSurfaceTextureUpdated,这就足够了,从onSurfaceTextureUpdated拿SurfaceTexture也一样
@Override public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) { //不再从这里获取到surface //surface = new Surface(surfaceTexture); } @Override public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int width, int height) { } @Override public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) { if (surface != null) { surface.release(); } return false; } @Override public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) { if (surface == null) { surface = new Surface(surfaceTexture); } }
后续再调用mMediaPlayer.setSurface(surface);就有画面了。
转载地址:http://harki.baihongyu.com/