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 < supportedFormat.length; i++)
{
mainForm.append("" + supportedFormat[i] + " : "
+ Sound.getConcurrentSoundCount(supportedFormat[i]));
}
}
display.setCurrent(mainForm);
}
protected void pauseApp()
{
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException
{
}
新闻热点
疑难解答