网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > J2EE/J2ME
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.J2MEMobile3D入门教程系列文章之.
.JBOSS4.0 JDBC数据源配置大全(二).
.hibernate源码浅析(net.sf.hibe.
.如何用IIS来实现OTA下载.
.在myeclipse下配置oc4j.
.介绍MIDP的属性问题.
.JBOSSAOP学习笔记-Mixin类和多重.
.介绍MIDP应用程序的属性.
.查询手机支持的多媒体类型和协议.
.J2ME设备的实际性能.
.Servlet容器工作原理(一).
.Spring入门.
.JavaMail快速入门-6.
.如何写自己的Type3JDBC驱动.
.JBOSSAOP学习笔记-AOP基本知识.
.快速开发web程序:用WebWork、JSP.
.用Spring改进J2EE编程.
.使用J2EE建立基于XML的网络服务.
.J2EE的展现层设计:Applets、serv.
.宠物店大战 (J2EE 与 .NET).

熟练使用J2ME可选包MMAPI

发表日期:2007-12-23


    了解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 picture try { byte[] pngImage = vc.getSnapshot(null); // do something with the image ... } catch (MediaException me) { }


    在后面的文章中我们将通过完整的实例演示如何使用MMAPI开发应用程序。  

(出处:)


上一篇:两种HTTP连接方式POST&GET的比较 人气:732
下一篇:介绍J2ME的安全结构 人气:782
浏览全部J2EE/J2ME的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐