adding sound!

i am trying to add sound to my game and have found this implementation

try {
InputStream is = getClass().getResourceAsStream(“song.mid”);
Player audioPlayer = Manager.createPlayer(is, “audio/midi”);
audioPlayer.start();
} catch (IOException ioe) {
} catch (MediaException me) { }

problem is i keep getting a compliation error pointing to the ‘is’ in the second line with the manager, saying its an incompatible type. i have imported java.io, util, the microedition.media and media.control, where am i going wrong?

any ideas?

cheers
beta test the current game @
www.pistachiomonkey.com

I can’t see any problems - my code looks just like yours and works. Try downloading and building Forum Nokia’s MIDP 2.0 game example “Sheepdog”, which contains similar code; if you can’t get that to build, you’ll know the problem is in your build tools or environment.

Beware of using relative filenames like “song.mid” in getResourceAsStream (or Image’s createImage) - you’re more likely to succeed by always using absolute filenames like “/song.mid”.

thank you david, once again!

i have downloaded and complied the sheepdog example with success, and refrenced the midi file appropriatly but i continue to get an incompatible type error pointing to the use of ‘is’ on the Manager.createPlayer?? it says required type is Player?

have also made sure that i am importing the media API, aggghh :o

so frustrted with this as it seems so easy?

any other pointers guys?

Please could you show us the exact text of the error message?

cheers David,

here’s the returned complier build errors:

C:\WTK22\apps\Monkey Madness\src\MadnessMIDlet.java:434: incompatible types
found : javax.microedition.media.Player
required: Player
Player audioPlayer = Manager.createPlayer( is , “audio/midi”);
^(this hat apperas under the 1st paranthases’(’)
C:\WTK22\apps\Monkey Madness\src\MadnessMIDlet.java:435: cannot resolve symbol
symbol : method start ()
location: class Player
audioPlayer.start();
^(this hat apperas under the first dot .)
2 errors
com.sun.kvem.ktools.ExecutionException
Build failed

here are my imports:
import javax.microedition.midlet.;
import javax.microedition.lcdui.
;
import javax.microedition.lcdui.game.;
import javax.microedition.rms.
;
import javax.microedition.media.;
import javax.microedition.media.control.
;
import java.util.;
import java.io.
;

um the method that does this call is in the MIDlet. is there any other info you need to diagnose this situation

many thanks for your time

Nick

Does your own source code include a class called Player? Perhaps representing your game’s user? Maybe the compiler thinks that “Player audioPlayer” is this kind of Player, not the javax.microedition.media.Player kind? If so, the solution is to write:

javax.microedition.media.Player audioPlayer = <etc…>

david you are a true legand!

my monkey can now battle to the sweet guitar rifts of Luarance Juber’s pass the buck! simply sensational! ;D