Sound via J2ME

I’m new to developing mobile java app’s, and have immediatly hit a wall :slight_smile:

I’m trying to play a sound from my disk, and through various sources have come to the following



        try {
//        Manager.playTone(64,1000,100);
        Player p;
        InputStream is = null;
                
        is=getClass().getResourceAsStream("wmpaud1.wav");
        p = Manager.createPlayer(is, "audio/x-wav"); 
        p.setLoopCount(1); // Play it once
        p.realize();
        p.prefetch();
        p.start();
        } catch(IOException ioe) {
        } catch(MediaException e) {
        }

Actually, when i change the filename, i get an IllegalArgumentException, so my guess is that the sound is indeed found.

However, whatever i do, the sound doesn’t play, is there an error in my ways?

Thanks :slight_smile:
Breens Jan

You could compare your code with the example in the MMAPI spec, which I seem to remember does just the same thing. I don’t have it on this PC though.

Some obvious things come to mind:

[]what do you mean by “play a sound from my disk”? With this code you can only play a sound from your MIDlet’s JAR file. (Or perhaps your build directory if you’re using an emulator to run the MIDlet classes before packaging as a JAR)
[
]you’re specifying a relative filename, which means that it gets prepended with your class’s package name (with slashes instead of dots); more often it’s useful to specify an absolute pathname, i.e. “/wmpaud1.wav”, to get a file in your JAR’s root directory
[]stupid question, but is your phone set to silent?
[
]are you sure that your phone (or emulator’s emulated phone) supports WAV? For example, Nokia 6230 doesn’t support WAV or any kind of sampled sound format in MMAPI