Java Reference
In-Depth Information
public void startRecording() {
try {
player = Manager.createPlayer("capture://video");
player.addPlayerListener(this);
player.realize();
//set up recording
record = (RecordControl) player.getControl("RecordControl");
record.setRecordSizeLimit(300000);
conn = (FileConnection) Connector.open(PATH, Connector.READ_WRITE);
if (!conn.exists())
conn.create();
stream = conn.openOutputStream();
record.setRecordStream(stream);
// Grab the video control and set it to the current display.
control = (VideoControl) player.getControl("VideoControl");
if (control != null) {
control.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this);
control.setDisplaySize(getWidth(), getHeight());
control.setVisible(true);
} player.start();
record.startRecord();
} catch (Exception e) {
Alert error = new Alert("Error", e.toString(), null, AlertType.ERROR);
Display.getDisplay(midlet).setCurrent(erro);
e.printStackTrace();
}
}
The code sets up a Player whose locator is capture://video ,
then proceeds to use the RecordControl ,a FileConnection (JSR-
75) and an output stream to record video from the camera and save it
on the device's permanent storage. This code works well on Symbian OS
devices supporting video recording in Mobile Media API. However, if
any of the operations attempted here is not supported, for example, video
recording on Nokia S60 2nd Edition or Series 40 3rd Edition devices, an
error message is displayed which offers little useful information to the
user. For example, if fetching the video stream from the camera is not
supported, a cryptic message, 'Invalid Locator', is shown. This illustrates
the need to perform all the required run-time checks, when using MMAPI,
and handle errors gracefully. In some cases, the MIDlet may still work
with limited functionality. For a video-recording application, however
this is unlikely.
In our example, we must check for the MMAPI system properties in
Table 9.1 before attempting to record video. Failing gracefully in this
case also means giving the user a readable and self-explanatory error
notification. Our corrected code example would then look like:
public void startRecording() {
if(!System.getProperty("supports.video.capture").equals("true")) {
Search WWH ::




Custom Search