0

I created a audio player using following code.

try {

    InputStream is = getClass().getResourceAsStream("bell.wav");

    player = Manager.createPlayer(is, "audio/X-wav");

    player.realize();

    player.prefetch();
    player.start();


}
catch (IOException ex) {
    ex.printStackTrace();

}
catch (MediaException ex) {
    ex.printStackTrace();

}

This code works on the simulator without any problem. But it is not working in the phone. MediaException is thrown. I think phone does not support for this player. Have there any solutions for this ?

Triad sou.
  • 2,969
  • 3
  • 23
  • 27
Tharanga
  • 117
  • 3
  • 10
  • did you try `createPlayer(is, "audio/wav")` or `createPlayer(is, "wav")`? Also when on the phone you could display [Alert](http://download.oracle.com/javame/config/cldc/ref-impl/midp2.0/jsr118/javax/microedition/lcdui/Alert.html) with the text of `ex.getMessage()` from within MediaException catch block to find more details - did you consider that? – gnat Sep 30 '11 at 17:31
  • yes I displayed a message under the mediaexception so that message is displayed on the phone but audio is started in the simulator without any problem. – Tharanga Oct 01 '11 at 14:11
  • what was the message on the phone? Also, does your phone support MIDP 2 (JSR 118)? I ask because per my recollection `wav` format is required to be supported by MIDP 2 – gnat Oct 01 '11 at 18:13
  • Message is not added for this code. I appended a message to form when error checking. Phone supports for MIDP2. I tried createPlayer(is, "audio/X-wav") it works on the simulator but createPlayer(is, "wav") does nit work, which gives a mediaException in simulator also. – Tharanga Oct 02 '11 at 03:30
  • what about `"audio/wav"`? - did you try it? – gnat Oct 02 '11 at 17:25
  • you mean, `"audio/wav"` is working both in emulator and in the real prhone, right? – gnat Oct 03 '11 at 09:24
  • No it is working in only simulator. – Tharanga Oct 04 '11 at 02:54
  • interesting. Did you try to see the output of [Manager.getSupportedContentTypes](http://download.oracle.com/javame/config/cldc/ref-impl/midp2.0/jsr118/javax/microedition/media/Manager.html#getSupportedContentTypes(java.lang.String)) at the device? also, what is the size of your wav file? – gnat Oct 04 '11 at 13:08
  • No I didn't try that. My wav file size is 528KB. – Tharanga Oct 05 '11 at 02:50

1 Answers1

1

It might help to check what mime types are supported by the device by checking

Manager.getSupportedContentTypes(String protocol);

and

Manager.getSupportedProtocols(String content_type);

You can also try using an URL instead of InputStream

Manager.createPlayer(String url);
Rikus Louw
  • 78
  • 7