WAP之家:为您提供最全最新的WAP技术,CP.SP.3G等行业资讯。 WAP之家交流论坛全新开放 点击进入>>
WAP资讯 | 3G动态 | SP动态 | 运营商动态 | 内容商动态 | 制造商动态 | 论坛讨论>> 每次自动访问
WAP技术 | WAP源码 | 手机编程 | 手机源码 | 无线技术 | J2ME技术 | 手机软件 添加到收藏夹
IVR技术 | SP资料 | SMS MMS技术 | 商业方案 | IVR下载 | 书籍教程 | 工具软件 语言:繁體中文

WAP之家技术文章J2ME技术程序开发熟练使用J2ME可选包MMAPI

熟练使用J2ME可选包MMAPI
作者:未知  来源:www.00muzhi.com  发布时间:2005-7-15 14:49:34
本文的目的是为读者提供处理不同情况的代码,您可以参考MMAPI DOC。
  1. 播放单音
    try {
    Manager.playTone(ToneControl.C4, 5000 /* millisec */, 100 /* max vol */);
    } catch (MediaException e) { }
  2. 简单媒体重放功能实现
    try {
    Player p = Manager.createPlayer("http://webserver/music.mp3");
    p.setLoopCount(5);
    p.start();
    } catch (IOException ioe) {
    } catch (MediaException me) { }
  3. 详细重放控制
    static final long SECS_TO_MICROSECS = 1000000L;
    Player p;
    VolumeControl vc;
    try {
    p = Manager.createPlayer("http://webserver/music.mp3");
    p.realize();
    // Set a listener.
    p.addPlayerListener(new Listener());
    // Grab volume control for the player.
    // Set Volume to max.
    vc = (VolumeControl)p.getControl("VolumeControl");
    if (vc != null)
    vc.setLevel(100);
    // Set a start time.
    p.setMediaTime(5 * SECS_TO_MICROSECS);
    // Guarantee that the player can start with the smallest latency.
    p.prefetch();
    // Non-blocking start
    p.start();
    } catch (IOException ioe) {
    } catch (MediaException me) { }
    class Listener implements PlayerListener {
    public void playerUpdate(Player p, String event, Object eventData) {
    if (event == END_OF_MEDIA || event == STOP_AT_TIME) {
    System.out.println("Done processing");
    try {
    p.setMediaTime(5 * SECS_TO_MICROSECS);
    p.start();
    } catch (MediaException me) { }
    break;
    }
    }
    }
  4. 实现MIDI重放控制
    Player p;
    TempoControl tc;
    
    try {
        p = Manager.createPlayer("http://webserver/tune.mid");
        p.realize();
    
        // Grab the tempo control.
        tc = (TempoControl)p.getControl("TempoControl");
        tc.setTempo(120000); // 120 beats/min
        p.start();
    
    } catch (IOException ioe) {
    } catch (MediaException me) { }
    
  5. 视频重放功能实现
    Player p;
    VideoControl vc;
    
    try {
        p = Manager.createPlayer("http://webserver/movie.mpg");
        p.realize();
    
        // Grab the video control and set it to the current display.
        vc = (VideoControl)p.getControl("VideoControl");
        if (vc != null) {
            Form form = new Form("video");
            form.append((Item)vc.initDisplayMode(vc.USE_GUI_PRIMITIVE, null));
            Display.getDisplay(midlet).setCurrent(form);
        }
    
        p.start();
    
    } catch (IOException ioe) {
    } catch (MediaException me) { }
    
  6. 播放RMS内存储的数据
    RecordStore rs;
    int recordID;
       :  // code to set up the record store.
    
    try {
        InputStream is = new
        ByteArrayInputStream(rs.getRecord(recordID));
        Player p = Manager.createPlayer(is, "audio/X-wav");
        p.start();
    } catch (IOException ioe) {
    } catch (MediaException me) { }
  7. 播放Jar文件中存储的媒体
    /** Notice that in MIDP 2.0, the wav format is mandatory only */
    /** in the case that the device supports sampled audio.       */
    
    try {
        InputStream is = getClass().getResourceAsStream("audio.wav");
        Player p = Manager.createPlayer(is, "audio/X-wav");
        p.start();
    } catch (IOException ioe) {
    } catch (MediaException me) { }
    
  8. 不同Player的同步
    Player p1, p2;
    
    try {
        p1 = Manager.createPlayer("http://webserver/tune.mid");
        p1.realize();
        p2 = Manager.createPlayer("http://webserver/movie.mpg");
        p2.realize();
        p2.setTimeBase(p1.getTimeBase());
        p1.prefetch();
        p2.prefetch();
        p1.start();
        p2.start();
    } catch (IOException ioe) {
    } catch (MediaException me) { }
    
  9. 产生单音序列
    byte tempo = 30; // set tempo to 120 bpm
    byte d = 8; // eighth-note

    byte C4 = ToneControl.C4;;
    byte D4 = (byte)(C4 + 2); // a whole step
    byte E4 = (byte)(C4 + 4); // a major third
    byte G4 = (byte)(C4 + 7); // a fifth
    byte rest = ToneControl.SILENCE; // rest

    byte[] mySequence = {
    ToneControl.VERSION, 1, // version 1
    ToneControl.TEMPO, tempo, // set tempo
    ToneControl.BLOCK_START, 0, // start define "A" section
    E4,d, D4,d, C4,d, E4,d, // content of "A" section
    E4,d, E4,d, E4,d, rest,d,
    ToneControl.BLOCK_END, 0, // end define "A" section
    ToneControl.PLAY_BLOCK, 0, // play "A" section
    D4,d, D4,d, D4,d, rest,d, // play "B" section
    E4,d, G4,d, G4,d, rest,d,
    ToneControl.PLAY_BLOCK, 0, // repeat "A" section
    D4,d, D4,d, E4,d, D4,d, C4,d // play "C" section
    };

    try{
    Player p = Manager.createPlayer(Manager.TONE_DEVICE_LOCATOR);
    p.realize();
    ToneControl c = (ToneControl)p.getControl("ToneControl");
    c.setSequence(mySequence);
    p.start();
    } catch (IOException ioe) {
    } catch (MediaException me) { }
  10. 语音捕获和录音功能的实现
    try {
        // Create a DataSource that captures live audio.
        Player p = Manager.createPlayer("capture://audio");
        p.realize();
        // Get the RecordControl, set the record locat

[1] [2]  下一页

[] [返回上一页] [打 印]
文章评论

用户名: 查看更多评论

分 值:100分 85分 70分 55分 40分 25分 10分 0分

内 容:

         (注“”为必填内容。) 验证码: 验证码,看不清楚?请点击刷新验证码