Troubleshooting guide

53
2: Using graphics and multimedia
// Play "C" section
D4, duration, D4, duration, E4, duration, D4, duration, C4, duration
};
try{
Player p = Manager.createPlayer(Manager.TONE_DEVICE_LOCATOR);
p.realize();
ToneControl c = (ToneControl)p.getControl("ToneControl");
c.setSequence(mySequence);
p.start();
} catch (IOException ioe) {
} catch (MediaException me) { }
Code sample: Creating a player for media from an input stream
Example: Play an MP3 audio file
//First we determine the supported content types
String types[] = Manager.getSupportedContentTypes(null);
for (int cnt = types.length - 1; cnt >= 0; --cnt) {
if (types[cnt].equals("audio/mpeg")) {
try {
//Retrieve the MP3 file
Class clazz = Class.forName("com.rim.samples.AudioDemo");
InputStream is = clazz.getResourceAsStream("/ TarzanYell.mp3");
//Create an instance of the player from the InputStream
Player player = javax.microedition.media.Manager.createPlayer
(is, "audio/mpeg");
player.realize();
player.prefetch();
//start the player
player.start();
} catch (Exception ex) { }
}
else if (types[cnt].equals("audio/x-wav ")) {
//this is where you would play wav files
}
else if (types[cnt].equals("audio/midi ")) {
//this is where you would play midi files
}
}
}