新的位置,新的要求

 今天在方军的blog上看到德鲁克的七次经历
其中有一句话感触很深:在新的岗位上,我现在应该怎样做才能发挥效能? – 迫使自己在新的环境里对自己提出新的要求.这一点觉得目前做的还是不够,可能是习惯性的懒于思考(勤于做事而缺少思考有时候更耽误事).来香港这么长时间,感觉自己虽然做事效率提高,但是性质似乎没有变过.也就是仍然是很单纯的技术角色,而不是一个多面手.虽然有时候也可以独挡一面,但”工程师性格”又会让自己退回到从前的角色. 思考中….

美国人的世界观

今天在Mr6的blog上看到这段话,挺有意思.

聯合國對全世界各國做了一項問卷調查,題目是:「請描述你對世界上其他地方食物短缺的意見」。後來這個調查在世界各國做了一圈,卻從來沒有得到任何效果, 徹底失敗,為什麼呢?因為非洲人看不懂甚麼叫做「食物」,東歐及亞洲人不知道甚麼叫做「意見」,西歐人不知道甚麼叫做「短缺」,南美人不知道甚麼叫做 「請」。 而美國人呢? 美國人不知道甚麼叫做「世界上其他地方」!

面相和心理学

有时候觉得其实那些算命的就是研究心理学的.人的长相其实有一种暗示的作用,不仅仅是对别人,也是对自己.所以似乎就存在一种命运和面相的关联.最近没有研究这方面的东西,只是忽有所感. 比如我这张愤青式的脸,如果是让算面先生说,可能会说”你命中30岁之前会犯小人”.因为如果脸长得不够”自信”(既是自己觉得有信心,也是别人觉得有信心)的话,别人就会倾向于challenge你的想法….这种challenge有时候就会让你觉得遇到小人.看你如何来处理这种challenge,如果用消极的做法,可能以后越来越愤青(性格和长相),以至于一生都是”犯了小人”,而如果积极的去处理的话,可能明年就不会犯了…

人的心都是脆弱的,很容易被鸟东西影响…但如果经常想想,可能会让自己的心更清晰.

转贴一些关于MMAPI的样例代码

本文的目的是为读者提供处理不同情况的代码,您可以参考MMAPI DOC。

播放单音

try
{
Manager.playTone(ToneControl.C4, 5000
/* millisec */, 100 /* max vol */);
} catch (MediaException e)
{
}

简单媒体重放功能实现:

try
{
Player p = Manager.createPlayer
(“http://webserver/music.mp3”);
p.setLoopCount(5);
p.start();
} catch (IOException ioe)
{
} catch (MediaException me)
{
}

详细重放控制:

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;
}
}
}

实现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)
{
}

视频重放功能实现:

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)
{
}

播放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)
{
}

播放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)
{
}

不同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)
{
}

产生单音序列

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);
}

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录音

try {
    // Create a Player that captures live audio.
    Player p = Manager.createPlayer("capture://audio");
    p.realize();
    // Get the RecordControl, set the record stream,
    // start the Player and record for 5 seconds.
    RecordControl rc = (RecordControl)p.getControl("RecordControl");
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    rc.setRecordStream(output);
    rc.startRecord();
    p.start();
    Thread.currentThread().sleep(5000);
    rc.commit();
    p.close();
 } catch (IOException ioe) {
 } catch (MediaException me) {
 } catch (InterruptedException ie) { }