简体   繁体   中英

Android - TextureView + SurfaceHolder.Callback

I wanted to know if it is possible to use SurfaceHolder.Callback (and of course its callbacks) in combination with TextureView?

I mean sth. like the following:

public class MainActivity extends AppCompatActivity implements  SurfaceHolder.Callback {

    private TextureView mTextureView;

    @Override
    public void surfaceCreated(SurfaceHolder surfaceHolder) {

    }

    @Override
    public void surfaceChanged(SurfaceHolder surfaceHolder, int format, int width, int height) {

    }

    @Override
    public void surfaceDestroyed(SurfaceHolder surfaceHolder) {

    }
}

Would that be working? The reason I ask is that whenever I see SurfaceHolder.Callback, they use SurfaceView.

No you can't. For TextureView you should use SurfaceTextureListener . In many senses these callbacks are similar to SurfaceHolder callbacks.

For example, instead of

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    mPreviewSurface = holder.getSurface();
}

you can write

@Override
public void onSurfaceTextureAvailable(SurfaceTexture texture, int width, int height) {
    mPreviewSurface = new Surface(texture);
}

See https://github.com/google/ExoPlayer/issues/98 . Thanks to @BrentM .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM