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); }
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) { }
语音捕捉和录音功能的实现
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); }