安卓TextureView.SurfaceTextureListener在相机API中无法使用

问题描述 投票:0回答:1

在过去的3年里,我一直在使用Camera API 2,所有的工作都是完美的,但最近10天都不能工作。 目前 TextureView.SurfaceTextureListener 没有被调用,所以相机预览是打不开的,打开就是黑屏。请问相关相机API2有什么问题或更新吗?请看下面的代码...

  textureView = (TextureView) findViewById(R.id.texture);
    assert textureView != null;
    textureView.setSurfaceTextureListener(textureListener);


TextureView.SurfaceTextureListener textureListener = new TextureView.SurfaceTextureListener() {
    @Override
    public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {   //open your camera here
        openCamera();
    }

    @Override
    public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {   // Transform you image captured size according to the surface width and height
    Log.e("onSurfaceTexture","onSurfaceTextureSizeChanged");
    }

    @Override
    public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
        Log.e("onSurfaceTexture","onSurfaceTextureDestroyed");
        return false;
    }

    @Override
    public void onSurfaceTextureUpdated(SurfaceTexture surface) {
        Log.e("onSurfaceTextureUpdated","onSurfaceTextureUpdated");
    }
};

在上面的代码工作完美的过去3年,但在前10天 TextureView.SurfaceTextureListener 行不通 openCamera 方法没有被调用,所以显示黑屏。請教如何解決這個問題。

android camera android-camera android-camera2
1个回答
0
投票

我也有同样的问题,但我的问题是通过在manifest文件中添加一行来解决的,即android:hardwareAccelerated="true"。

© www.soinside.com 2019 - 2024. All rights reserved.