应用Nokia UI API处理声音问题

2008-01-05 10:35:42  作者
Nokia UI API的目的在于提供一些MIDP1.0中没有提供的功能,本文讲述如何使用Nokia UI中提供的声音处理的API。在com.nokia.mid.sound包中有一个Sound类和SoundListener接口,SoundListener接口的作用就是当播放的状态转换的时候,监听器中的方法被调用,也就是我们常说的回调。这里不做介绍了。

Sound类封装了用于播放声音的方法,手机所能支持的声音格式和并行播放的数量是和设备相关的,我们可以通过方法supportedFormat = Sound.getSupportedFormats();
Sound.getConcurrentSoundCount()方法得到这些数据。下面提供一个小程序用户判定我的手机nokia 6108所能支持的声音类型和并行播放的数量。

package com.j2medev.test;

import Javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import com.nokia.mid.sound.*;

public class NokiaSound extends MIDlet
{

private Display display;

private Form mainForm;

private int[] supportedFormat;

protected void startApp() throws MIDletStateChangeException
{

initMIDlet();

}

public void initMIDlet()
{
display = Display.getDisplay(this);
mainForm = new Form("Nokia Sound");
supportedFormat = Sound.getSupportedFormats();
if (supportedFormat.length == 0)
{
mainForm.append("No audio format supported!");
} else
{
for (int i = 0; i %26lt; supportedFormat.length; i++)
{
mainForm.append("" + supportedFormat[i] + " : "
+ Sound.getConcurrentSoundCount(supportedFormat[i]));
}
}
display.setCurrent(mainForm);
}

protected void pauseApp()
{

}

protected void destroyApp(boolean arg0) throws MIDletStateChangeException
{

}