而Audio封装了player调用的细节,你可以从http://www.cnblogs.com/Files/zhengyun_ustc/TwinsMusic-Effect2-withNokiaUIAPISound.rar和http://www.cnblogs.com/Files/zhengyun_ustc/TwinsMusic-Effect1.rar下载我的源代码,
更多信息可看http://www.cnblogs.com/zhengyun_ustc/archive/2005/11/23/playsounds2.html:
public class Audio implements PlayerListener
{
。。。。
/**
* Creates a player for specified sound
* and popuplates the Player array.
* @param snd The sound to create
*/
protected void createSound(int snd) throws Exception
{
System.out.println("Audio::createSound snd>>" + snd);
{
int rsc = 0;
String type = TYPE_MIDI;
switch(snd)
{
case MUSIC:
rsc = CommandResources.SND_JAZZY;
break;
case BEEP:
type = TYPE_WAVE;
rsc = CommandResources.SND_WAVE_BEEP;
break;
case END:
type = TYPE_WAVE;
rsc = CommandResources.SND_WAVE_END;
break;
case TIMEOUT:
type = TYPE_WAVE;
rsc = CommandResources.SND_WAVE_TIMEOUT;
break;
case XUXU:
type = TYPE_WAVE;
rsc = CommandResources.SND_WAVE_XUXU;
break;
case CHANGJIN:
type = TYPE_AMR;
rsc = CommandResources.SND_AMR_CHANGJIN;
break;
case MESSAGE:
type = TYPE_MIDI;
rsc = CommandResources.SND_MESSAGE;
break;
}
InputStream isInputMusic = CommandResources.getResource(rsc);
if(isInputMusic != null)
{
System.out.println("Audio::createSound createPlayer Begin:" + type);
m_sounds[snd] =
Manager.createPlayer(isInputMusic, type);
System.out.println("Audio::createSound createPlayer End");
if (snd == MUSIC || snd == CHANGJIN)
{
System.out.println("loop intro tune for ever and ever!");
m_sounds[snd].setLoopCount(-1); // loop intro tune for ever and ever
m_sounds[snd].realize();
// Set Volume.
VolumeControl volume = (VolumeControl)
m_sounds[snd].getControl("VolumeControl");
if (volume != null)
volume.setLevel(35);// 小点声!!
}
}
else
{
System.out.println("ERROR!Cannot find music resource!");
}