Hi. I'm new in developing J2ME games and now I'm programming a game which has to play several MIDI sounds in Nokia 5140.
This is my code:
- I create the player in the constructor of a class named SoundManager (it also implements PlayerListener):
InputStream is = getClass().getResourceAsStream("/audio/disparar.mid");
firePlayer = Manager.createPlayer(is, "audio/midi");
firePlayer.addPlayerListener(this);
- And the code to play the sound is this:
if (currentPlayer != null) {
currentPlayer.stop();
currentPlayer.deallocate();
while (playing) {}
}
currentPlayer = firePlayer;
firePlayer.realize();
firePlayer.prefetch();
firePlayer.start();
playing = true;
public void playerUpdate(Player player, String str, Object obj) {
if (str == PlayerListener.END_OF_MEDIA) {
playing = false;
} else if (str == PlayerListener.STOPPED) {
playing = false;
}
}
It works for Nokia 6230 emulator, but when I take it to the Nokia 5140 it crashes and shows a java.lang.NullPointerException.
Does anyone knows what is wrong in my code?
or
Could anyone tell me how to do this?
Can Nokia 5140 play MIDI sounds or only wav ones?

Reply With Quote

