本文的目的是为读者提供处理不同情况的代码,您可以参考MMAPI DOC。
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) { }
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) { }
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) { }
/** 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) { }
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) { }
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) { }
实现摄像功能
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.VeVb.com)
新闻热点
疑难解答