y Jonathan Knudsen
July 2003 Download: [source code] The Mobile Media API (MMAPI) enables MIDlets to play and record audio and video data. The exact capabilities depend on the device implementation. Currently the only device that supports MMAPI is the Nokia 3650 mobile phone. This article describes how to build a simple camera application using MMAPI. Tools for MMAPI Development The first challenge of building an MMAPI application is finding the right tools. The J2ME Wireless Toolkit 2.0 includes support for MIDP 2.0, MMAPI 1.0, and WMA 1.1. At first glance, it looks like this is all you need — but the Nokia 3650 runs MIDP 1.0, not MIDP 2.0. To develop MIDP 1.0 applications, you'll need the 1.0.4 version of the J2ME Wireless Toolkit and an emulator that supports MMAPI. Sun offers such an emulator, available from the MMAPI home page. While this emulator will allow you to build MMAPI applications, it does not support image capture, so it can't be used to test a camera application. Nokia has an emulator that does support image capture, part of the Nokia Series 60 MIDP Concept SDK Beta 0.2, available from Forum Nokia, Nokia's developer web site. The file name is nS60_jme_concept_sdk_b0_2_014.zip. Linux developers should be able to use the Nokia Developer's Suite for J2ME, Version 2.0. The following installation instructions apply to Windows only. Install the Nokia SDK in the <J2ME Wireless Toolkit>\wtklib\devices directory (or copy the Nokia_Series_60_MIDP_Concept_SDK_Beta_0_2 directory there after installation is complete). Next time you run the J2ME Wireless Toolkit, you'll have an additional emulator available, Nokia_Series_60_MIDP_Concept_SDK_Beta_0_2. When this emulator is selected, you can build MMAPI applications and test them as well. The emulator itself looks very much like the Nokia 3650. MMAPI Device Testing There's no substitute for testing on real devices. In the long term, many devices will support MMAPI, even though the Nokia 3650 is the only MMAPI device available just now. There are several ways to deploy a MIDlet on the Nokia 3650. I transfer files via infrared between my laptop and the device. You can also use Bluetooth or do an OTA installation. Getting a Video Capture Player The first step in taking pictures (officially called video capture) in a MIDlet is obtaining a
If the device does not support video capture, a The
Showing the Camera Video The video coming from the camera can be displayed on the screen either as an
If you wish to show the video coming from the camera in a
Showing the camera video in a
Capturing an Image Once the camera video is shown on the device, capturing an image is easy. All you need to do is call The
The image returned by the Nokia 3650's MMAPI implementation is 160 x 120 pixels. Although the camera is capable of 640 x 480 (which is what you get with the native camera application), the MMAPI implementation on this phone can't handle the higher resolution. Creating a Thumbnail Image One seemingly simple thing I wanted to do in this article was talk about how to create a thumbnail image, a smaller version of the image captured from the camera. MIDP 2.0 includes methods for obtaining the raw pixel values of an The solution I implemented is neither elegant nor strictly correct (in an image-processing sense), but it approximates the behavior I wanted and doesn't involve parsing the PNG format. I create a new (blank) image for the thumbnail. For each pixel of that image, I set the clipping region to encompass that single pixel, and draw the source image at an appropriately scaled location.
The Snapper Example The source code download for this article is an example application called Snapper. Snapper allows you to take pictures and shows in a Snapper is smart enough to figure out whether video capture is supported; try running it on Sun's MMEmulator, for example, and you'll receive a polite message:
If you use the Nokia Concept emulator instead, you'll see a screen like this:
Choose the Camera command (the Nokia implementation places this in the Options menu). On a real device, you'll see live video coming from the camera; the emulator shows a single still picture. In either case,
To take a picture, choose Capture or press the Fire button (in the center of the arrow buttons). Snapper creates a thumbnail and shows it on the MIDlet's main screen.
Each time you take another picture, a thumbnail image is added to the main screen. Future Directions The Snapper example is simple, but there are many interesting places you could take it:
Summary The Mobile Media API is a flexible and powerful API that allows the rendering and capture of audio and video data. This article describes how to use MMAPI's video capture capability, what tools you'll need, and how to use them to write MIDlets that take pictures. The Snapper example allows you to take pictures and creates smaller thumbnail images. With a little work, the Snapper example could easily be the basis of a networked image-sharing application. |
|