国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

熟練使用J2ME可選包MMAPI

2019-11-18 16:08:36
字體:
來源:轉載
供稿:網友
    了解J2ME可選包MMAPI一文向讀者介紹了MMAPI的基本知識,掌握MMAPI的靈活性應該是重點。本文將講述如何在實際開發中使用MMAPI。

    本文的目的是為讀者提供處理不同情況的代碼,您可以參考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 location, and     // start the Player and record for 5 seconds.    RecordControl rc = (RecordControl)p.getControl("RecordControl");    rc.setRecordLocation("file:/tmp/audio.wav");    rc.startRecord();    p.start();    Thread.currentThread().sleep(5000);    p.stop();    rc.stopRecord();    rc.commit();} catch (IOException ioe) {} catch (MediaException me) {} catch (InterruptedException e) { }
  11. 實現攝像功能
    Player p;VideoControl vc;// initialize camera try { p = Manager.createPlayer("capture://video"); 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) { }// now take a picturetry { byte[] pngImage = vc.getSnapshot(null); // do something with the image ...} catch (MediaException me) { }


    在后面的文章中我們將通過完整的實例演示如何使用MMAPI開發應用程序。  

(出處:http://www.survivalescaperooms.com)



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 呼和浩特市| 休宁县| 北辰区| 津市市| 高平市| 惠安县| 百色市| 砀山县| 怀化市| 阿鲁科尔沁旗| 新平| 连江县| 崇州市| 白城市| 武夷山市| 钦州市| 翁源县| 阿瓦提县| 和静县| 仲巴县| 色达县| 赤壁市| 大连市| 石城县| 辽宁省| 开阳县| 张北县| 孝感市| 喀喇沁旗| 万源市| 桃园县| 云林县| 新源县| 新和县| 兴国县| 宜川县| 额敏县| 新余市| 廊坊市| 荃湾区| 尚志市|