Java Reference
In-Depth Information
Tip The AMMS API that JSR 234 defines provides a lot more than better control over imaging sensors. It also
includes interfaces for advanced audio features such as 3D audio localization, reverberation, and equalizers; radio
tuner control; effects for layering and grouping Player instances; and media postprocessing. If you're working on
multimedia applications for high-end Java ME devices, be sure to see if the devices you target support this API.
The getSnapshot method obviously only works for capturing a single frame from a
video data source. Your application may want to record other data sources, such as the
audio stream from the microphone for a voice recorder or music-recognition application.
To capture other kinds of media, you use the RecordControl interface, which writes a copy
of the recorded media to an OutputStream instance. Listing 16-8 shows an example
derived from the documentation for JSR 135.
Listing 16-8. Pseudocode Demonstrating the RecordControl Interface
try {
// Create a DataSource that captures live audio.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Player p = Manager.createPlayer("capture://audio");
p.realize();
RecordControl rc = (RecordControl)p.getControl("RecordControl");
rc.setRecordStream(baos);
rc.startRecord();
p.start();
Thread.currentThread().sleep(5000);
p.stop();
rc.stopRecord();
rc.commit();
byte[] b = baos.toByteArray();
} catch (IOException ioe) {}
catch (MediaException me) {}
catch (InterruptedException e) {}
This example creates a Player instance that captures the current audio for five sec-
onds, and it gets an array of bytes to the encoded data that was captured. You can then
use this content elsewhere. For example, you can use it as data that you write to a file,
upload to a web server for processing, or send via the WMA as an MMS enclosure (which
I discuss in Chapter 14).
When using a RecordControl instance, the MMAPI usually encodes the resulting data
in the same format as the source. When recording from captured devices, you can find
out the supported encoding scheme through the values of the audio.encodings and
video.encodings system properties.
 
Search WWH ::




Custom Search