Netbeans + J2ME - Can't play .au files?!

Started by
4 comments, last by BigMarv 17 years ago
Having a bit of a play with Netbeans & J2ME. In the following example that .au file will just not play - no exceptions, just no sound. The wav code above it however plays fine. Anyone got any suggestions as to why? Many thanks in advance. Marv. P.S. the phone emulator is the +5550000 Default Colour Phone. P.P.S. In case it was an error with my original .au file I downloaded piano.au from http://simplythebest.net/sounds/other_formats/Sun_Audio/sound_effects_AU/instruments_au.html but still no joy :( public void playTune() { try { //InputStream is = getClass().getResourceAsStream("battle8kh.wav"); //Player p = Manager.createPlayer(is, "audio/X-wav"); InputStream is = getClass().getResourceAsStream("piano.au"); Player p = Manager.createPlayer(is, "audio/basic"); p.start(); } catch (IOException ioe) { } catch (MediaException me) { } }
Advertisement
I am pretty sure the default WTK does not have MIME type information for .au files. If you catch a simple Exception, not an IOException of MediaException, what does the exception say (System.out.println(e.getMessage())? By the way you will also get problems if you try and play .AMR files as well, there is no default support.
Hi Trojanman

Nothing from a standard exception either :(

So what will I need to get the au files working - or should I change the file format to mp3 (want to keep file sizes low if possible).

The thing is, I thought au files were the most compatible format for mobile phones (shows what I know).

Many thanks

Paul.
Okay - after a bit more researching I've decided to go with the amr format instead as this sounds like the most compatible.

public void playTune() {
try
{
InputStream is = getClass().getResourceAsStream("battle.amr");

Player p = Manager.createPlayer(is, "audio/amr");

p.start();
}
catch (IOException ioe) {System.out.println(ioe.getMessage()); }
catch (MediaException me) {System.out.println(me.getMessage()); }
catch (Exception e) {System.out.println(e.getMessage()); }
}

Only problem I've got now is that instead of sound, the emulator gives the exception: "Cannot create a Player for: audio/amr", but I think this may be because my PC can't play amr files.

Anyone know how I can get it to play the amr files via the emulator (if this is indeed the problem).

Many thanks

Marv.
What handset are you developing for? Or is this emulator only?

You will learn this, but I will tell you anyways, audio in J2ME is a PITA and more often than not does not work as expected on the handset. As a rule I only play Midi files, in the emulator and on the handset I know support it I will attempt to play some .wav files. The emulator does not have mime types for .amr but some of the handset emulators might (Nokia, SE, Samsung, etc.).
Quote:Original post by trojanman
What handset are you developing for? Or is this emulator only?

You will learn this, but I will tell you anyways, audio in J2ME is a PITA and more often than not does not work as expected on the handset. As a rule I only play Midi files, in the emulator and on the handset I know support it I will attempt to play some .wav files. The emulator does not have mime types for .amr but some of the handset emulators might (Nokia, SE, Samsung, etc.).


Cheers TM

I'm trying to make the game as compatible as possible, and without wave style effects I'll probably have difficulty.

I'll stick with wavs until it runs completely under emulator and then play with the sounds - maybe do a couple of different versions.

Thanks again

Marv.

This topic is closed to new replies.

Advertisement