Code example for Surface

0
    } 
 
    @Override 
    public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
        textureView.setLayoutParams(new FrameLayout.LayoutParams(480, 320, Gravity.CENTER));
        player.setSurface(new Surface(surface));
        player.start();
        textureView.setScaleX(0.5f);
        textureView.setScaleY(0.5f);
    } 
 
    @Override 
    public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {}
 
    @Override 
    public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
        player.stop();
        player.release();
        return true; 
    }