应用Nokia UI API处理声音问题[1]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

作者:mingjava 文章来源:http://www.j2medev.com/Article/ShowArticle.asp?ArticleID=147

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 < supportedFormat.length; i++)
            {
                mainForm.append("" + supportedFormat[i] + " : "
                        + Sound.getConcurrentSoundCount(supportedFormat[i]));
            }
        }
        display.setCurrent(mainForm);
    }

    protected void pauseApp()
    {

    }

    protected void destroyApp(boolean arg0) throws MIDletStateChangeException
    {

    }

}

程序运行在nokia 6108上显示1:1表示本机支持单音,并行播放数量也是1。

本文关键:应用Nokia UI API处理声音问题
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top