Caution :
- this snippet is NOT compatible with the current 1.0.1 statble release of Kuix.
- this snippet is only and example of possible usage
If you checkout the lastest development sources of Kuix, you would be able to extends the UnpaintableWidget class.
public class Camera extends UnpaintableWidget { private Player player; private VideoControl videoControl; public Camera() { super("camera"); try { player = Manager.createPlayer("capture://video"); player.realize(); videoControl = (VideoControl) player.getControl("VideoControl"); videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, Kuix.getCanvas()); videoControl.setVisible(true); } catch (IOException e) { e.printStackTrace(); } catch (MediaException e) { e.printStackTrace(); } try { player.start(); } catch (MediaException e) { e.printStackTrace(); } } protected void doLayout() { super.doLayout(); videoControl.setDisplayLocation(getDisplayX(), getDisplayY()); try { videoControl.setDisplaySize(getWidth(), getHeight()); } catch (MediaException e) { e.printStackTrace(); } } }
Unpaintable widget permit to create a widget which is exclude from the screen repaint process. This is important if you use, like above, the native video player. Because it internaly repaint a portion of the screen in its own thread.
To integrate this custom widget into your app, follow this method. |
I had to add this to get things to layout properly
public Metrics getPreferredSize(int w) {
Metrics metrics = new Metrics(this);
metrics.width = videoControl.getDisplayWidth();
metrics.height = videoControl.getDisplayHeight();
return metrics;
}