Troubleshooting guide

52
BlackBerry Java Development Environment Development Guide
Code sample: Creating a player for a sequence of tones
Example: Sequence of tones
// "Mary Had A Little Lamb" has "ABAC" structure
// Use block to repeat "A" section
byte tempo = 30; // 30 x 4 = tempo of 120 bpm
byte duration = 8; // Note length 8 (quaver) = 1/8th of a note duration
byte C4 = ToneControl.C4; // C note value = 60 (middle C)
byte D4 = (byte)(C4 + 2); // D note value = 62 (a whole step)
byte E4 = (byte)(C4 + 4); // E note value = 64 (a major third)
byte G4 = (byte)(C4 + 7); // G note value = 67 (a fifth)
byte rest = ToneControl.SILENCE; // rest
byte[] mySequence = {
ToneControl.VERSION, 1, // version 1
ToneControl.TEMPO, tempo, // set tempo
//
// Start define "A" section
ToneControl.BLOCK_START, 0,
//
// Content of "A" section
E4, duration, D4, duration, C4, duration, E4, duration,
E4, duration, E4, duration, E4, duration, rest, duration,
//
// End define "A" section
ToneControl.BLOCK_END, 0,
//
// Play "A" section
ToneControl.PLAY_BLOCK, 0,
//
// Play "B" section
D4, duration, D4, duration, D4, duration, rest, duration,
E4, duration, G4, duration, G4, duration, rest, duration,
//
// Repeat "A" section
ToneControl.PLAY_BLOCK, 0,
//
Create a player for media
from an input stream.
1. Invoke Manager.createPlayer(InputStream stream, String type).
The type parameter represents the input media content type.
2. Check for a MediaException if null is the content type.
RecordStore recSt;
int recId;
try {
InputStream inpStr = new
ByteArrayInputStream((store.getRecord(recId));
Player p = Manager.createPlayer(inpStr, "audio/mpeg");
p.start();
} catch (IOException ioEx) {
} catch (MediaException meEx) {}
Task Steps