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
{
}
新聞熱點
疑難解答