Java Reference
In-Depth Information
Let us now give a concrete example of the integration of Camera
functionality. The following code snippet demonstrates how to take a
picture using the phone camera:
Player p;
VideoControl vc;
// initialize camera
try
p = Manager.createPlayer("capture://video");
p.realize();
// Grab the video control and set it to the current display.
vc = (VideoControl)p.getControl("VideoControl");
if (vc != null)
{
Form form = new Form("video");
form.append((Item)vc.initDisplayMode(vc.USE_GUI_PRIMITIVE, null));
Display.getDisplay(midlet).setCurrent(form);
}
p.start();
byte[] image = vc.getSnapshot(null);
// do something with the image ...
}
{
catch (IOException ioe)
}
catch (MediaException me)
{}
An application that uses a camera could be expected to use
Video-
Control
to manage the display (from the JSR-135 point of view, a
camera attached to a device does not differ from any other video con-
tent); it could also be expected to use
RecordControl
and other
supported and relevant Controls (e.g.,
RateControl
). The multime-
dia subsystem support for the functionality of this specific use-case is
shared between ECam, which defines the
CCamera
class, and MMF,
which defines
CVideoRecorderUtility
. Therefore the bottom layer
in JSR-135 instantiates the two objects and uses their high-level API
to delegate the functionality operations. For example, calling
CCam-
era::CaptureImage()
when
VideoControl.getSnapshot()
is
invoked or
CVideoRecorderUtility::Record()
in response to
invoking
RecordControl
methods.
Although we did not go into the fine-grained details of the integration,
this single example demonstrates well how using the MMF, which is
also designed as a high-level API, to delegate functionality to the native
subsystem is done using only a limited number of native operations. In
the same way, MIDI and audio are played using
CMidiClientUtility
and
CMdaAudioPlayerUtility
respectively; and conversion between
different image formats is performed using the multimedia ICL subsystem.
However, there are still cases where the MMAPI implementation has to
perform tasks which are not taken care of by the MMF. One example is the
controlled fetching of audio playback data when a locator input string is
provided. The preferred way is to use the MMF API to get the content from
a URL (e.g.,
CMdaAudioPlayerUtility::OpenUrlL()
). However,
if this feature is not supported at run time, the MMAPI implementation