Skip to main content

How to use wav player locally on Windows CE 5.0 core?

5 replies [Last post]
jkp
Offline
Joined: 2009-09-06
Points: 0

I'm trying to get a gps navigation midlet, gpsmid (http://gpsmid.sourceforge.net/) running on a Windows CE device. There's trouble with sound - a tone sequence created with Manager.createPlayer(Manager.TONE_DEVICE_LOCATOR); will work, but I cannot seem to get stream audio to work.

With the default amr local audio files, I get "Failed to create resource player for /in.amr:
javax.microedition.media.MediaExceptioN: Player cannot be created
for type audio/amr: Player cannot be created for type audio/amr" which suggest to me the amr format might not be supported.

When trying with .wav files (mime type audio/x-wav), the result is

"Failed to create resource player for /prepare.wav:
java.lang.NullPointerException: 0: 0"

the code is:

try {
InputStream is = getClass().getResourceAsStream(soundFile);
if (is != null) {
//#debug debug
mLogger.debug("Got Inputstream for " + soundFile);
String mediaType = null;
if (soundFile.toLowerCase().endsWith(".amr") ) {
mediaType = "audio/amr";
} else if (soundFile.toLowerCase().endsWith(".wav") ) {
mediaType = "audio/x-wav";
} else if (soundFile.toLowerCase().endsWith(".mp3") ) {
mediaType = "audio/mpeg";
} else if (soundFile.toLowerCase().endsWith(".ogg") ) {
mediaType = "audio/x-ogg";
}
player = Manager.createPlayer(is, mediaType);
if (player!=null) {
//#debug debug
mLogger.debug("created player for " + soundFile);
player.realize();
//#debug debug
mLogger.debug("realized player for " + soundFile);
player.addPlayerListener( this );
VolumeControl volCtrl = (VolumeControl) player.getControl("VolumeControl");
volCtrl.setLevel(100);
}
//#debug debug
else mLogger.debug("Could NOT CREATE PLAYER for " + mediaType);
}
//#debug debug
else mLogger.debug("RESOURCE NOT FOUND: " + soundFile);
} catch (Exception ex) {
mLogger.exception("Failed to create resource player for " + soundFile, ex);
player = null;
}

phoneme is phoneME Feature - MIDP rev19166 (zip) downloaded from http://www.cs.kuleuven.be/~davy/phoneme/index.php?q=node/10

Should local wav files be supported on this phoneme version? If so, any ideas on what's going wrong?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
davyp
Offline
Joined: 2007-01-03
Points: 0

Hi jkp,

As you might have noticed, the audio playback implementation on WinCE is far from
complete. I basically implemented a few things so that some audio test midlets would
work. The current implementation uses the basic common audio playback methods
of WinCE. I do not use DirectSound as some WinCE devices might not support it.

This also means that ogg/mp3/amr are unsupported. wav files should work if they
are not compressed. I.e. they should have a plain Microsoft PCM encoding. I have a
midlet that plays a wav file (a Microsoft PCM, 8 bit, mono 22050 Hz one) as follows:

InputStream in = getClass().getResourceAsStream("/whew.wav");
Player p = Manager.createPlayer(in, "audio/x-wav");
p.start();

Supporting the full JSR 135 spec requires a lot more work. If anyone knows of an
open source implementation of JSR 135 for WinCE, I am always interested.

Davy

jkp
Offline
Joined: 2009-09-06
Points: 0

Thanks, so it should work for a simple wav file. I converted the wav file to 8 bit mono 22050 Hz (was not compressed 16-bit 8000 Hz I think), but still I get the same null pointer error.

Gpsmid code seems to do exactly the same thing as your example does, but in addition it has

player.addPlayerListener( this );
VolumeControl volCtrl = (VolumeControl) player.getControl("VolumeControl");
volCtrl.setLevel(100);

Should addPlayerListener() work? If that's not implemented, maybe that's the problem. Or maybe I'm overlooking some other difference.

I guess I'll have to do some checking and debugging on what goes wrong and to find out if your simple example works for me.

jkp
Offline
Joined: 2009-09-06
Points: 0

> Gpsmid code seems to do exactly the same thing as
> your example does, but in addition it has
>
> player.addPlayerListener( this );
> VolumeControl volCtrl = (VolumeControl)
> player.getControl("VolumeControl");
> volCtrl.setLevel(100);
>
> Should addPlayerListener() work? If that's not
> implemented, maybe that's the problem. Or maybe I'm
> overlooking some other difference.

OK, problem solved, it was the two volume control lines which caused the null pointer error. After removing them, the sounds work! The 16-bit 8000Hz sound works too, so no need for conversion.

davyp
Offline
Joined: 2007-01-03
Points: 0

Correct,

It is the line player.getControl() that is currently not implemented. It follows the specification by
returning null if the interface is not supported and since it currently does not support any control,
it returns null by default.

http://java.sun.com/javame/reference/apis/jsr135/javax/microedition/medi...
http://java.sun.com/javame/reference/apis/jsr135/javax/microedition/media/Controllable.html#getControl(java.lang.String)

Davy

jkp
Offline
Joined: 2009-09-06
Points: 0

> It is the line player.getControl() that is currently
> not implemented. It follows the specification by
> returning null if the interface is not supported and
> since it currently does not support any control,
> it returns null by default.

OK, so this can clearly be classified as a bug in gpsmid. The simple solution is to skip the setLevel call if the result is null, which I tested after the last post and works fine, and posted on a gpsmid forum.