views:

301

answers:

3

I need to play music (this is the only sound in my game). So far I've written this, but it keeps giving me errors:

"incompatible types"

Here's my sound code:

try {
    InputStream is = getClass().getResourceAsStream("/sound.wav");
    Player p = Manager.createPlayer(is, "/X-wav");
    p.start();
} catch (IOException ioe) { 
} catch (MediaException me) { 
}

The error occurs in line 3;

+1  A: 

use Manager static functions to figure out supported mime types on the target phone.

/X-wave strikes me as wrong, although it's been quite some time since I touched j2me.

Omry
+5  A: 

Specifically, try "audio/wav" instead of "X/-wav"; otherwise, see what Manager.getSupportedContentTypes() returns.

Neil Coffey
A: 

Neil is right, check for the supported types first. Most phones to support mid and mp3. Wav file are supported in some phones, but the size of a wav file is large so it eats up memory and jar space so it is not recommended

Ram