Help Center
Local Navigation
- Working with multimedia in a BlackBerry device application
-
Creating a BlackBerry device application that plays media
- Create a BlackBerry device application that plays media
- Code Sample: Playing media from a URI
- Code sample: Playing a sequence of tones
- Create a BlackBerry device application that plays media from an input stream
- Create a BlackBerry device application that plays streaming media
- Play a video in a UI field in a BlackBerry device application
- Create a BlackBerry device application that takes a photograph using the camera
- Create a BlackBerry device application that sends audio to a Bluetooth enabled device
- Create a Content Handler application that plays media
- Code Sample: Create a Content Handler application that plays media
- Specifying the features of a BlackBerry device application that plays media
- Responding to user input
-
Streaming media in a BlackBerry device application
- RIMM streaming video file
- RIM proprietary video format (RIMM streaming file)
- Buffer and play streamed media
- Code sample: Streaming media in a BlackBerry device application
- Code Sample: Reading data from a buffer
- Code Sample: Streaming media from a file on the BlackBerry device
- Code sample: Parsing a RIMM streaming video file
- Recording media by using a BlackBerry device application
- Playing media in the BlackBerry device media application
-
Creating a BlackBerry device application that plays media
- Working with images from the camera application
- Drawing and positioning images
- Displaying images
- Using unprocessed images
- Using encoded images
- Using SVG content in a BlackBerry device application
- Creating 2-D and 3-D graphics by using JSR-239
- Glossary
- Provide feedback
- Document revision history
- Legal notice
BlackBerry Manuals & Help
>
Developer Documentation
>
Java Development Guides and API Reference
>
Development Guide
Multimedia - BlackBerry Java Application - 5.0
Record audio in a BlackBerry device application
A
BlackBerry® device can record audio in four formats:
Adaptive Multi-Rate (AMR), 8 kHz mono-16-bit pulse code modulation (PCM), GSM
with
BlackBerry devices operating on GSM networks,
and QCP with
BlackBerry devices operating on CDMA networks.
The default audio recording format is AMR.
-
Import the required classes.
import java.lang.Thread; import javax.microedition.media.Manager; import java.io.ByteArrayOutputStream; import javax.microedition.media.Player; import javax.microedition.media.control.RecordControl;
-
In a class that extends
Thread, create a variable of type
Player, a variable of type
RecordControl for recording media from a
Player, a variable of type
ByteArrayOutputStream for the audio stream, and a
byte array variable to store the
OutputStream data. Note that you are not required to
record audio in a separate thread because recording operations are threaded by
design.
final class AudioRecorderThread extends Thread { private Player _player; private RecordControl _rcontrol; private ByteArrayOutputStream _output; private byte _data[]; -
Create a class constructor.
AudioRecorderThread(){} - In a try block, in your implementation of the run() method, invoke Manager.createPlayer(String locator) using as a parameter a value that specifies the encoding to use to record audio. You can use the following supported locator strings.
-
Create a
Player object by invoking
createPlayer() to capture audio.
public void run() { try { _player = Manager.createPlayer("capture://audio"); -
Invoke
Player.realize().
_player.realize();
-
Invoke
Player.getControl() to obtain the controls for
recording media from a
Player.
_rcontrol = (RecordControl)_player.getControl("RecordControl"); -
Create a
ByteArrayOutputStream to record the audio stream.
Note that you can also record directly to a file specified by a URL.
_output = new ByteArrayOutputStream();
-
Invoke
RecordControl.setRecordStream() to set the output
stream to which the
BlackBerry device application records data.
_rcontrol.setRecordStream(_output);
-
Invoke
RecordStore.startRecord() to start recording the
audio and start playing the media from the
Player.
_rcontrol.startRecord(); _player.start();
-
In a catch block, specify actions to perform if an exception
occurs.
} catch (final Exception e){ //Perform actions } -
Create a try block in your implementation of the stop method, and
then invoke
RecordControl.commit() to stop recording audio.
public void stop() { try { _rcontrol.commit() -
Invoke
ByteArrayOutputStream.toByteArray() to write the
audio data from the
OutputStream to a byte array.
_data = _output.toByteArray();
-
Invoke
ByteArrayOutputStream.close() and
Player.close() to close the
OutputStream and
Player.
_output.close(); _player.close();
-
In a catch block, specify actions to perform if an exception
occurs.
} catch (Exception e) { //Perform actions }
Next topic: Code sample: Recording audio from a Player
Previous topic:
Recording media by using a BlackBerry device application