Sunday, February 4, 2018

Android TextureView Example

A TextureView can be used to display a content stream. Such a content stream can for instance be a video or an OpenGL scene. The content stream can come from the application's process as well as a remote process.

If you want to display a live video stream or any content stream such as video or an OpenGL scene, you can use TextureView provided by android in order to do that.
In order to use TextureView, all you need to do is get its SurfaceTexture.The SurfaceTexture can then be used to render content. In order to do this, you just need to do instantiate an object of this class and implement SurfaceTextureListener interface. Its syntax is given below 


private TextureView myTexture;
public class MainActivity extends Activity implements SurfaceTextureListener{
   protected void onCreate(Bundle savedInstanceState) {
      myTexture = new TextureView(this);
      myTexture.setSurfaceTextureListener(this);
      setContentView(myTexture);
   }
}
@Override
public void onSurfaceTextureAvailable(SurfaceTexture arg0, int arg1, int arg2) {
}

@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture arg0) {
}

@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture arg0, int arg1,int arg2) {
}

@Override
public void onSurfaceTextureUpdated(SurfaceTexture arg0) {
}

No comments:

Post a Comment