Mar 31, 2009

How to use Mobile Media API with eSWT

On mobile Java world Mobile Media API (MMAPI, aka. JSR 135) is the API to use for playing videos and music as well as accessing the phone camera. Basically all the multimedia development is done through this API on mobile phones.
Video support and the camera support requires the MMAPI to be used together with the UI toolkit. Although there is plenty of information on the MMAPI, because eSWT is a young toolkit, it is hard to find information on how to use it together with eSWT.
The cue for using MMAPI and eSWT is in the way the VideoControl is initialized. The rest of the use is similar, if not same, to other toolkits.  Below is a snippet that shows how to initialize the VideoControl to use an eSWT Control. If you pay attention to line 5 of the snippet there is a call to Control.setParent(). This method must be called, regardless if the eSWT implementation supports reparenting or not. The actual initialization of the video to control actually takes place in this method. Initialization is delayed until this method is called because MMAPI does not provide a mechanism to provide arguments during control initialization and eSWT requires at least the parent Control to properly initialize.
1: Player player = Manager.createPlayer("capture://video");
2: player.realize();
3: VideoControl videoControl = (VideoControl) player.getControl("VideoControl");
4: Control vControl = (Control) videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, Control.class.getName());
5: vControl.setParent(shell);

A complete example that shows how to take a picture using eSWT and MMAPI can be found here.