Displaying a camera video into a Kuix app

2008-11-03 14:54
Submit by Tofu

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.


Tags: camera video Popularity: 1536

Comments

pandora808 2008-11-03 14:54

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;
    }