This may apply to other phones, but thats all I have
to test it on at the moment.
This bug does not occure in any emulator, only on a
real phone.
Basically, it appears that while the display is set
to an instance of "TextBox" sound will not play.
More so, any sound currently playing is cut off
the moment the display is set.
I have included part of my code below:
-------------------------------------------------------------------------
static final int SOUND_VOLUME = 1;
static Sound sound;
// sound function
public static void playSound(byte bytes[])
{
try
{
if (sound == null)
sound = new Sound(bytes, Sound.FORMAT_TONE);
if (sound.getState() == Sound.SOUND_PLAYING)
sound.stop();
sound.init(bytes, Sound.FORMAT_TONE);
sound.setGain(SOUND_VOLUME);
sound.play(1);
}
catch(Exception e)
{
showError(e.toString());
}
}
// a test function to show the problem
// (My real code uses a TextBox to get the players
// name for a highscore table, which is where my
// real problem is).
public void menuInfo()
{
sCurrentMenu = sInfo;
/*
// sound will work using this section
Form_Info = new Form("Info");
Form_Info.addCommand(Command_back);
Form_Info.addCommand(Command_ok);
Form_Info.setCommandListener(this);
Form_Info.append("some info");
display.setCurrent(Form_Info);
*/
// but not using this section
TextBox foo = new TextBox("Info", "some info!", 10, 0);
foo.addCommand(Command_ok);
foo.addCommand(Command_back);
foo.setCommandListener(this);
display.setCurrent(foo);
// load and play a sound (makes no difference
// if sound is preloaded, or loaded on the fly)
playSound(loadBinaryFile("/testsound.ott"));
}
// callback for Back and OK commands.
// back goes back to menu, ok just tries
// to play the sound again.
public void commandAction(Command c, Displayable d)
{
String sLabel = c.getLabel();
try
{
// -- SNIP --
if (sCurrentMenu.equals(sInfo))
{
if (sLabel.equals(sOK))
{
// play sound on OK, this is only to test if it will play
playSound(MyUtils.loadBinaryFile("/testsound.ott"));
}
else // ie == sBack
{
Form_Info = null;
menuMain();
}
}
// -- SNIP --
}
catch (Exception e)
{
ShowError(e.toString());
}
}
-------------------------------------------------------
As noted in the above code, if method, menuInfo()
uses an instance of class Form, the sound plays
on calling of the menuInfo() method, and plays
again if the OK callback event is sent.
However if you use a TextBox, the sound plays
for about 1/4 of a second and is then cut off,
when the method is called. The OK callback
produces no sound at all.
Anyone have any ideas ???
Alex


Reply With Quote

