<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MoDoFo.println(" &#187; j2me</title>
	<atom:link href="http://zhangv.com/archives/tag/j2me/feed" rel="self" type="application/rss+xml" />
	<link>http://zhangv.com</link>
	<description>Life for Idea - forever young</description>
	<lastBuildDate>Fri, 20 Jan 2012 01:32:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>如何javame调用goo.gl短网址服务</title>
		<link>http://zhangv.com/archives/1627</link>
		<comments>http://zhangv.com/archives/1627#comments</comments>
		<pubDate>Thu, 25 Nov 2010 18:19:19 +0000</pubDate>
		<dc:creator>zhangv</dc:creator>
				<category><![CDATA[技术(Tech)]]></category>
		<category><![CDATA[goo.gl]]></category>
		<category><![CDATA[j2me]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[javame]]></category>

		<guid isPermaLink="false">http://zhangv.com/?p=1627</guid>
		<description><![CDATA[直接上代码:
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import org.json.me.JSONObject;
public class GooglUtils {
private static String GOOGL_API_ENDPOINT="http://goo.gl/api/shorten?security_token=null&#38;url=";
public static String shorten(String url) throws Exception{
HttpConnection con = null;
InputStream in = null;
OutputStream out = null;
ByteArrayOutputStream bos = null;
OutputStreamWriter osw = null;
InputStreamReader isr = null;
byte[] request;
int messageLength;
try {
bos = new ByteArrayOutputStream();
osw = new OutputStreamWriter(bos, "UTF-8");
//            osw.write(url);
osw.flush();
request = bos.toByteArray();
messageLength [...]]]></description>
			<content:encoded><![CDATA[<p>直接上代码:</p>
<p>import java.io.ByteArrayOutputStream;<br />
import java.io.IOException;<br />
import java.io.InputStream;<br />
import java.io.InputStreamReader;<br />
import java.io.OutputStream;<br />
import java.io.OutputStreamWriter;</p>
<p>import javax.microedition.io.Connector;<br />
import javax.microedition.io.HttpConnection;</p>
<p>import org.json.me.JSONObject;</p>
<p>public class GooglUtils {<br />
private static String GOOGL_API_ENDPOINT="http://goo.gl/api/shorten?security_token=null&amp;url=";<br />
public static String shorten(String url) throws Exception{<br />
HttpConnection con = null;<br />
InputStream in = null;<br />
OutputStream out = null;<br />
ByteArrayOutputStream bos = null;<br />
OutputStreamWriter osw = null;<br />
InputStreamReader isr = null;<br />
byte[] request;<br />
int messageLength;</p>
<p>try {<br />
bos = new ByteArrayOutputStream();<br />
osw = new OutputStreamWriter(bos, "UTF-8");<br />
//            osw.write(url);<br />
osw.flush();</p>
<p>request = bos.toByteArray();<br />
messageLength = request.length;</p>
<p>con = (HttpConnection) Connector.open(GOOGL_API_ENDPOINT+url, Connector.READ_WRITE);<br />
con.setRequestMethod(HttpConnection.POST);<br />
con.setRequestProperty("Content-Length", Integer<br />
.toString(messageLength));<br />
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");<br />
out = con.openOutputStream();<br />
out.write(request);<br />
in = con.openInputStream();<br />
isr = new InputStreamReader(in,"UTF-8");</p>
<p>char[] buf = new char[256];<br />
int rsize = 0;<br />
StringBuffer sb = new StringBuffer();<br />
while((rsize=isr.read(buf))&gt;0){<br />
sb.append(buf,0,rsize);<br />
}<br />
System.out.println(sb.toString());</p>
<p>JSONObject jo = new JSONObject(sb.toString());<br />
String shorturl = (String) jo.get("short_url");<br />
System.out.println(shorturl);<br />
return shorturl;</p>
<p>} catch (Exception x) {<br />
throw x;<br />
} finally {<br />
try {<br />
if (con != null)<br />
con.close();<br />
if (in != null)<br />
in.close();<br />
if (out != null)<br />
out.close();<br />
} catch (IOException ioe) {<br />
ioe.printStackTrace();<br />
}<br />
}<br />
}<br />
}</p>

	Tags: <a href="http://zhangv.com/archives/tag/goo-gl" title="goo.gl" rel="tag">goo.gl</a>, <a href="http://zhangv.com/archives/tag/j2me" title="j2me" rel="tag">j2me</a>, <a href="http://zhangv.com/archives/tag/java" title="Java" rel="tag">Java</a>, <a href="http://zhangv.com/archives/tag/javame" title="javame" rel="tag">javame</a><br />
]]></content:encoded>
			<wfw:commentRss>http://zhangv.com/archives/1627/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>how big should the byte array be in java me(j2me)</title>
		<link>http://zhangv.com/archives/1020</link>
		<comments>http://zhangv.com/archives/1020#comments</comments>
		<pubDate>Wed, 20 May 2009 04:32:07 +0000</pubDate>
		<dc:creator>zhangv</dc:creator>
				<category><![CDATA[技术(Tech)]]></category>
		<category><![CDATA[j2me]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JME]]></category>

		<guid isPermaLink="false">http://zhangv.com/archives/1020</guid>
		<description><![CDATA[Keep getting the out of memory error when handling the image file in emulator(wtk) and device(e61i)
Just had a simple test and here is what I found:
The code is simple:
for(int i=1000;i&#60;Integer.MAX_VALUE;i++){
System.out.println(i);
byte[] buf = new byte[i];
}
and see when your program will crash. - Actually it won't crash, as the OOME(out of memory error), is an Error rather [...]]]></description>
			<content:encoded><![CDATA[<p>Keep getting the out of memory error when handling the image file in emulator(wtk) and device(e61i)<br />
Just had a simple test and here is what I found:<br />
The code is simple:<br />
for(int i=1000;i&lt;Integer.MAX_VALUE;i++){<br />
System.out.println(i);<br />
byte[] buf = new byte[i];<br />
}<br />
and see when your program will crash. - Actually it won't crash, as the OOME(out of memory error), is an Error rather RuntimeException, when the OOME is thrown, the program just go on.</p>
<p>Let's see the result:<br />
In wtk2.5.2 emulator: the size cannot beyond "2003765" byte(for comparison: we can reserve byte array of size  Integer.MAX_INTEGER/40 - 53687091 in standard version on my laptop).<br />
In e61i: not instrumented yet. My guess is maybe much smaller, as I had experience that OOME thrown when the image size is only 300k, what different is: the byte array CAN take up to that size, however error happened when handling the image(when trying to createImage from byte array).<br />
I followed this <a href="http://discussion.forum.nokia.com/forum/showthread.php?t=98259">thread </a>and the guys found that 400k bytes is the limit on nokia6681.</p>
<p>Another depressing result.</p>

	Tags: <a href="http://zhangv.com/archives/tag/j2me" title="j2me" rel="tag">j2me</a>, <a href="http://zhangv.com/archives/tag/java" title="Java" rel="tag">Java</a>, <a href="http://zhangv.com/archives/tag/jme" title="JME" rel="tag">JME</a><br />
]]></content:encoded>
			<wfw:commentRss>http://zhangv.com/archives/1020/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>S60里的系统属性</title>
		<link>http://zhangv.com/archives/157</link>
		<comments>http://zhangv.com/archives/157#comments</comments>
		<pubDate>Wed, 12 Mar 2008 10:09:57 +0000</pubDate>
		<dc:creator>zhangv</dc:creator>
				<category><![CDATA[技术(Tech)]]></category>
		<category><![CDATA[j2me]]></category>

		<guid isPermaLink="false">http://218.22.170.60/zhangv/wordpress/?p=411</guid>
		<description><![CDATA[http://www.forum.nokia.com/document/Java_ME_Developers_Library_v1/index.html?content=GUID-545CA84A-8378-4DFA-9035-94479F5BE26E.html
一些常用的路径，比如图像路径，存储卡路径，相机路径
 System properties
The table below contains the File API system properties that return the localized names of common directories and the URLs to the most common directories. Several Strings are only supported in either S60 or Series 40. Refer to the individual tables for each implementation.




String
Description


Fileconn.dir.photos.name
Localized name for the photo directory, for example "Images".


Fileconn.dir.graphics.name
Localized name for [...]]]></description>
			<content:encoded><![CDATA[<p>http://www.forum.nokia.com/document/Java_ME_Developers_Library_v1/index.html?content=GUID-545CA84A-8378-4DFA-9035-94479F5BE26E.html</p>
<p>一些常用的路径，比如图像路径，存储卡路径，相机路径</p>
<h1 class="pageHeading"> <strong>System properties</strong></h1>
<p>The table below contains the File API system properties that return the localized names of common directories and the URLs to the most common directories.<span> Several Strings are only supported in either S60 or Series 40. Refer to the individual tables for each implementation.</span></p>
<p class="tablenoborder"><a name="GUID-472EE630-D6DC-4EAE-A10F-EFA9B836DB52"></a></p>
<table id="GUID-472EE630-D6DC-4EAE-A10F-EFA9B836DB52" border="1" cellpadding="4" cellspacing="0" rules="all">
<thead align="left">
<tr class="title">
<th valign="top" width="47%">String</th>
<th valign="top" width="53%">Description</th>
</tr>
<tr>
<td headers="d0e45402 " valign="top" width="47%"><code>Fileconn.dir.photos.name</code></td>
<td headers="d0e45407 " valign="top" width="53%">Localized name for the photo directory, for example "<code>Images</code>".</td>
</tr>
<tr>
<td headers="d0e45402 " valign="top" width="47%"><code>Fileconn.dir.graphics.name</code></td>
<td headers="d0e45407 " valign="top" width="53%">Localized name for the graphic directory, for example "<code>Graphic clips</code>".</td>
</tr>
<tr>
<td headers="d0e45402 " valign="top" width="47%"><code>Fileconn.dir.music.name</code></td>
<td headers="d0e45407 " valign="top" width="53%">Localized name for the music directory, for example "<code>Music clips</code>".</td>
</tr>
<tr>
<td headers="d0e45402 " valign="top" width="47%"><code>Fileconn.dir.memorycard.name</code></td>
<td headers="d0e45407 " valign="top" width="53%">Localized UI name for the memory card of directory, for example "<code>Memory card</code>".</td>
</tr>
<tr>
<td headers="d0e45402 " valign="top" width="47%"><code>Fileconn.dir.photos</code></td>
<td headers="d0e45407 " valign="top" width="53%">The URL of the default storage directory for photos captured with the integrated camera and other images. For example, "<code>file:///c:/My files/Images/</code>".</td>
</tr>
<tr>
<td headers="d0e45402 " valign="top" width="47%"><code>Fileconn.dir.graphics</code></td>
<td headers="d0e45407 " valign="top" width="53%">The URL of the default storage directory for clip art graphics (caller group icons, background pictures, and other similar items). For example, "<code>file:///c:/My files/Graphic clips/</code>".</td>
</tr>
<tr>
<td headers="d0e45402 " valign="top" width="47%"><code>Fileconn.dir.music</code></td>
<td headers="d0e45407 " valign="top" width="53%">The URL of the default storage directory for music files (MP3, AAC, and others). For example, "<code>file:///c:/My files/Music clips/</code>".</td>
</tr>
<tr>
<td headers="d0e45402 " valign="top" width="47%"><code>Fileconn.dir.memorycard</code></td>
<td headers="d0e45407 " valign="top" width="53%">Root directory of memory card. For example, "<code>file:///e:/</code>".</td>
</tr>
</table>
<p><strong>Example<span> for S60</span></strong>:</p>
<p><code>String url = System.getProperty("fileconn.dir.photos") + "myImage.jpg";</code></p>
<p>The Content of the URL is <code>file:///c:/data/Images/myImage.jpg</code></p>
<p class="tablenoborder"><a name="GUID-E36E09A3-D0F3-46E8-BB1C-BBBD917E2906"></a></p>
<table id="GUID-E36E09A3-D0F3-46E8-BB1C-BBBD917E2906" border="1" cellpadding="4" cellspacing="0" rules="all">
<thead align="left">
<tr class="title">
<th valign="top" width="47%">String</th>
<th valign="top" width="53%">Description</th>
</tr>
<tr>
<td headers="d0e45755 " valign="top" width="47%"><code>Fileconn.dir.photos.name</code></td>
<td headers="d0e45760 " valign="top" width="53%">Localized name for the photo directory, for example "<code>Images</code>".</td>
</tr>
<tr>
<td headers="d0e45755 " valign="top" width="47%"><code>Fileconn.dir.graphics.name</code></td>
<td headers="d0e45760 " valign="top" width="53%">Localized name for the graphic directory, for example "<code>Graphic clips</code>".</td>
</tr>
<tr>
<td headers="d0e45755 " valign="top" width="47%"><code>Fileconn.dir.music.name</code></td>
<td headers="d0e45760 " valign="top" width="53%">Localized name for the music directory, for example "<code>Music clips</code>".</td>
</tr>
<tr>
<td headers="d0e45755 " valign="top" width="47%"><code>Fileconn.dir.memorycard.name</code></td>
<td headers="d0e45760 " valign="top" width="53%">Localized UI name for the memory card of directory, for example "<code>Memory card</code>".</td>
</tr>
<tr>
<td headers="d0e45755 " valign="top" width="47%"><code>Fileconn.dir.photos</code></td>
<td headers="d0e45760 " valign="top" width="53%">The URL of the default storage directory for photos captured with the integrated camera and other images. "<code>file:///C:/predefgallery/predefphotos</code>".</td>
</tr>
<tr>
<td headers="d0e45755 " valign="top" width="47%"><code>Fileconn.dir.graphics</code></td>
<td headers="d0e45760 " valign="top" width="53%">The URL of the default storage directory for clip art graphics (caller group icons, background pictures, and other similar items). "<code>file:///C:/predefgallery/predefgraphics</code>".</td>
</tr>
<tr>
<td headers="d0e45755 " valign="top" width="47%"><code>Fileconn.dir.music</code></td>
<td headers="d0e45760 " valign="top" width="53%">The URL of the default storage directory for music files (MP3, AAC, and others). "<code>file:///C:/predefgallery/predefmusic</code>".</td>
</tr>
<tr>
<td headers="d0e45755 " valign="top" width="47%"><code>Fileconn.dir.themes</code></td>
<td headers="d0e45760 " valign="top" width="53%">The URL of the default storage directory for themes. "<code>file:///C:/predefgallery/predefthemes</code>"</td>
</tr>
</table>
<p><strong>Example for Series 40</strong>:</p>
<p><code>String url = System.getProperty("fileconn.dir.photos") + "myImage.jpg";</code></p>
<p>The Content of the URL is <code>file:///C:/predefgallery/predefphotos/myimage.jpg</code></p>

	Tags: <a href="http://zhangv.com/archives/tag/j2me" title="j2me" rel="tag">j2me</a><br />
]]></content:encoded>
			<wfw:commentRss>http://zhangv.com/archives/157/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javablog » How MIDlet Signing is Killing J2ME</title>
		<link>http://zhangv.com/archives/155</link>
		<comments>http://zhangv.com/archives/155#comments</comments>
		<pubDate>Tue, 11 Mar 2008 12:54:32 +0000</pubDate>
		<dc:creator>zhangv</dc:creator>
				<category><![CDATA[技术(Tech)]]></category>
		<category><![CDATA[翻译]]></category>
		<category><![CDATA[j2me]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://218.22.170.60/zhangv/wordpress/?p=321</guid>
		<description><![CDATA[Javablog » How MIDlet Signing is Killing J2ME
TODO: 翻译

	Tags: 翻译, j2me, Java
]]></description>
			<content:encoded><![CDATA[<p><a href="http://javablog.co.uk/2007/08/09/how-midlet-signing-is-killing-j2me/">Javablog » How MIDlet Signing is Killing J2ME</a></p>
<p>TODO: 翻译</p>

	Tags: <a href="http://zhangv.com/archives/tag/%e7%bf%bb%e8%af%91" title="翻译" rel="tag">翻译</a>, <a href="http://zhangv.com/archives/tag/j2me" title="j2me" rel="tag">j2me</a>, <a href="http://zhangv.com/archives/tag/java" title="Java" rel="tag">Java</a><br />
]]></content:encoded>
			<wfw:commentRss>http://zhangv.com/archives/155/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>让VideoControl支持更高的分辨率</title>
		<link>http://zhangv.com/archives/154</link>
		<comments>http://zhangv.com/archives/154#comments</comments>
		<pubDate>Sun, 09 Mar 2008 02:38:03 +0000</pubDate>
		<dc:creator>zhangv</dc:creator>
				<category><![CDATA[技术(Tech)]]></category>
		<category><![CDATA[j2me]]></category>
		<category><![CDATA[mofire]]></category>

		<guid isPermaLink="false">http://218.22.170.60/zhangv/wordpress/?p=307</guid>
		<description><![CDATA[如果直接videoControl.getSnapshot(null)的话，得到的是默认的较低分辨率和画质-在我的e61i上是640*480，这样显然不能充分利用2M像素的相机。（当然也要看了，你指望从手机上传出多清晰的照片，而且也要有兼容的问题，万一其他手机支持不到这么高怎么办？）通过设置width和height即可以支持更高的分辨率。
videoControl.setVisible(false);
String enc = "encoding=jpeg&#38;width=800&#38;height=600";
byte[] raw = videoControl.getSnapshot(enc);
appendImage(raw);
在我的小6上测试:
1600*1200 - 无法处理的异常(应该是得到的byte[]太大，ME的Vector会溢出），1200*900 - MediaException : Symbian OS Error: -4，貌似不支持这个分辨率
1280*960 - 同上
1024*768 - 同上
800*600 -  成功
640*480 - 成功，默认的分辨率
参考：nokia.wiki

Powered by MoFire

	Tags: j2me, mofire
]]></description>
			<content:encoded><![CDATA[<p>如果直接videoControl.getSnapshot(null)的话，得到的是默认的较低分辨率和画质-在我的e61i上是640*480，这样显然不能充分利用2M像素的相机。（当然也要看了，你指望从手机上传出多清晰的照片，而且也要有兼容的问题，万一其他手机支持不到这么高怎么办？）通过设置width和height即可以支持更高的分辨率。</p>
<p>videoControl.setVisible(false);<br />
String enc = "<strong>encoding=jpeg&amp;width=800&amp;height=600</strong>";<br />
byte[] raw = videoControl.getSnapshot(<strong>enc</strong>);<br />
appendImage(raw);<br />
在我的小6上测试:<br />
1600*1200 - 无法处理的异常(应该是得到的byte[]太大，ME的Vector会溢出），1200*900 - MediaException : Symbian OS Error: -4，貌似不支持这个分辨率<br />
1280*960 - 同上<br />
1024*768 - 同上<br />
800*600 -  成功<br />
640*480 - 成功，默认的分辨率</p>
<p>参考：<a href="http://wiki.forum.nokia.com/index.php/Portal:Java_Code_Examples">nokia.wiki</a></p>
<p><a href="http://218.22.170.60/zhangv/wordpress/wp-content/uploads/1205032089069.jpg"><img src="http://218.22.170.60/zhangv/wordpress/wp-content/uploads/1205032089069.jpg" width="200" /></a><br />
Powered by MoFire</p>

	Tags: <a href="http://zhangv.com/archives/tag/j2me" title="j2me" rel="tag">j2me</a>, <a href="http://zhangv.com/archives/tag/mofire" title="mofire" rel="tag">mofire</a><br />
]]></content:encoded>
			<wfw:commentRss>http://zhangv.com/archives/154/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>转贴一些关于MMAPI的样例代码</title>
		<link>http://zhangv.com/archives/144</link>
		<comments>http://zhangv.com/archives/144#comments</comments>
		<pubDate>Sun, 02 Mar 2008 07:18:51 +0000</pubDate>
		<dc:creator>zhangv</dc:creator>
				<category><![CDATA[技术(Tech)]]></category>
		<category><![CDATA[j2me]]></category>

		<guid isPermaLink="false">http://218.22.170.60/zhangv/wordpress/?p=409</guid>
		<description><![CDATA[本文的目的是为读者提供处理不同情况的代码，您可以参考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 * [...]]]></description>
			<content:encoded><![CDATA[<p>本文的目的是为读者提供处理不同情况的代码，您可以参考MMAPI DOC。</p>
<p>播放单音</p>
<p>try<br />
{<br />
Manager.playTone(ToneControl.C4, 5000<br />
/* millisec */, 100 /* max vol */);<br />
} catch (MediaException e)<br />
{<br />
}</p>
<p>简单媒体重放功能实现:</p>
<p>try<br />
{<br />
Player p = Manager.createPlayer<br />
("http://webserver/music.mp3");<br />
p.setLoopCount(5);<br />
p.start();<br />
} catch (IOException ioe)<br />
{<br />
} catch (MediaException me)<br />
{<br />
}</p>
<p>详细重放控制:</p>
<p>static final long SECS_TO_MICROSECS<br />
= 1000000L;<br />
Player p;<br />
VolumeControl vc;<br />
try {<br />
p = Manager.createPlayer<br />
("http://webserver/music.mp3");<br />
p.realize();<br />
// Set a listener.<br />
p.addPlayerListener(new Listener());<br />
// Grab volume control for the player.<br />
// Set Volume to max.<br />
vc = (VolumeControl)p.getControl<br />
("VolumeControl");<br />
if (vc != null)<br />
vc.setLevel(100);<br />
// Set a start time.<br />
p.setMediaTime(5 * SECS_TO_MICROSECS);<br />
// Guarantee that the player<br />
can start with the smallest latency.<br />
p.prefetch();<br />
// Non-blocking start<br />
p.start();<br />
} catch (IOException ioe)<br />
{<br />
} catch (MediaException me)<br />
{<br />
}<br />
class Listener implements PlayerListener<br />
{<br />
public void playerUpdate(Player p,<br />
String event, Object eventData)<br />
{<br />
if (event == END_OF_MEDIA<br />
|| event == STOP_AT_TIME)<br />
{<br />
System.out.println<br />
("Done processing");<br />
try {<br />
p.setMediaTime<br />
(5 * SECS_TO_MICROSECS);<br />
p.start();<br />
} catch (MediaException me)<br />
{<br />
}<br />
break;<br />
}<br />
}<br />
}</p>
<p>实现MIDI重放控制:</p>
<p>Player p;<br />
TempoControl tc;</p>
<p>try {<br />
p = Manager.createPlayer<br />
("http://webserver/tune.mid");<br />
p.realize();</p>
<p>// Grab the tempo control.<br />
tc = (TempoControl)p.getControl<br />
("TempoControl");<br />
tc.setTempo(120000);<br />
// 120 beats/min<br />
p.start();</p>
<p>} catch (IOException ioe)<br />
{<br />
} catch (MediaException me)<br />
{<br />
}</p>
<p>视频重放功能实现:</p>
<p>Player p;<br />
VideoControl vc;</p>
<p>try {<br />
p = Manager.createPlayer<br />
("http://webserver/movie.mpg");<br />
p.realize();</p>
<p>// Grab the video control<br />
and set it to the current display.<br />
vc = (VideoControl)p.getControl<br />
("VideoControl");<br />
if (vc != null)<br />
{<br />
Form form = new Form("video");<br />
form.append<br />
((Item)vc.initDisplayMode<br />
(vc.USE_GUI_PRIMITIVE, null));<br />
Display.getDisplay(midlet)<br />
.setCurrent(form);<br />
}</p>
<p>p.start();</p>
<p>} catch (IOException ioe)<br />
{<br />
} catch (MediaException me)<br />
{<br />
}</p>
<p>播放RMS内存储的数据:</p>
<p>RecordStore rs;<br />
int recordID;<br />
:　// code to set up the record store.</p>
<p>try {<br />
InputStream is = new<br />
ByteArrayInputStream<br />
(rs.getRecord(recordID));<br />
Player p = Manager.createPlayer<br />
(is, "audio/X-wav");<br />
p.start();<br />
} catch (IOException ioe)<br />
{<br />
} catch (MediaException me)<br />
{<br />
}</p>
<p>播放Jar文件中存储的媒体</p>
<p>/** Notice that in MIDP 2.0,<br />
the wav format is mandatory only */<br />
/** in the case that the<br />
device supports sampled audio.　*/</p>
<p>try {<br />
InputStream is =<br />
getClass().getResourceAsStream<br />
("audio.wav");<br />
Player p = Manager.createPlayer<br />
(is, "audio/X-wav");<br />
p.start();<br />
} catch (IOException ioe)<br />
{<br />
} catch (MediaException me)<br />
{<br />
}</p>
<p>不同Player的同步</p>
<p>Player p1, p2;</p>
<p>try {<br />
p1 = Manager.createPlayer<br />
("http://webserver/tune.mid");<br />
p1.realize();<br />
p2 = Manager.createPlayer<br />
("http://webserver/movie.mpg");<br />
p2.realize();<br />
p2.setTimeBase(p1.getTimeBase());<br />
p1.prefetch();<br />
p2.prefetch();<br />
p1.start();<br />
p2.start();<br />
} catch (IOException ioe)<br />
{<br />
} catch (MediaException me)<br />
{<br />
}</p>
<p>产生单音序列</p>
<p>byte tempo = 30;<br />
// set tempo to 120 bpm<br />
byte d = 8;<br />
// eighth-note</p>
<p>byte C4 = ToneControl.C4;<br />
byte D4 = (byte)(C4 + 2);<br />
// a whole step<br />
byte E4 = (byte)(C4 + 4);<br />
// a major third<br />
byte G4 = (byte)(C4 + 7);<br />
// a fifth<br />
byte rest = ToneControl.SILENCE;<br />
// rest</p>
<p>byte[] mySequence = {<br />
ToneControl.VERSION, 1,<br />
// version 1<br />
ToneControl.TEMPO, tempo,<br />
// set tempo<br />
ToneControl.BLOCK_START, 0,<br />
// start define "A" section<br />
E4,d, D4,d, C4,d, E4,d,<br />
// content of "A" section<br />
E4,d, E4,d, E4,d, rest,d,<br />
ToneControl.BLOCK_END, 0,<br />
// end define "A" section<br />
ToneControl.PLAY_BLOCK, 0,<br />
// play "A" section<br />
D4,d, D4,d, D4,d, rest,d,<br />
// play "B" section<br />
E4,d, G4,d, G4,d, rest,d,<br />
ToneControl.PLAY_BLOCK, 0,<br />
// repeat "A" section<br />
D4,d, D4,d, E4,d, D4,d, C4,d<br />
// play "C" section<br />
};</p>
<p>try{<br />
Player p = Manager.createPlayer<br />
(Manager.TONE_DEVICE_LOCATOR);<br />
p.realize();<br />
ToneControl c = (ToneControl)<br />
p.getControl("ToneControl");<br />
c.setSequence(mySequence);<br />
p.start();<br />
} catch (IOException ioe)<br />
{<br />
} catch (MediaException me)<br />
{<br />
}</p>
<p>语音捕获和录音功能的实现</p>
<p>try<br />
{<br />
// Create a DataSource that<br />
captures live audio.<br />
Player p = Manager.createPlayer<br />
("capture://audio");<br />
p.realize();<br />
// Get the RecordControl,<br />
set the record l<a href="http://www.ourexam.com/Shop/ORACLE/200605/Shop_33.html" class="channel_keylink">oca</a>tion, and<br />
// start the Player and<br />
record for 5 seconds.<br />
RecordControl rc =<br />
(RecordControl)p.getControl<br />
("RecordControl");<br />
rc.setRecordL<a href="http://www.ourexam.com/Shop/ORACLE/200605/Shop_33.html" class="channel_keylink">oca</a>tion<br />
("file:/tmp/audio.wav");<br />
rc.startRecord();<br />
p.start();<br />
Thread.currentThread()<br />
.sleep(5000);<br />
p.stop();<br />
rc.stopRecord();<br />
rc.commit();<br />
} catch (IOException ioe)<br />
{<br />
} catch (MediaException me)<br />
{<br />
} catch (InterruptedException e)<br />
{<br />
}</p>
<p>实现摄像功能</p>
<p>Player p;<br />
VideoControl vc;</p>
<p>// initialize camera<br />
try {<br />
p = Manager.createPlayer<br />
("capture://video");<br />
p.realize();</p>
<p>// Grab the video control<br />
and set it to the current<br />
display.<br />
vc = (VideoControl)p.getControl<br />
("VideoControl");<br />
if (vc != null)<br />
{<br />
Form form =<br />
new Form("video");<br />
form.append((Item)vc.initDisplayMode<br />
(vc.USE_GUI_PRIMITIVE, null));<br />
Display.getDisplay(midlet).setCurrent(form);<br />
}</p>
<p>p.start();</p>
<p>} catch (IOException ioe)<br />
{<br />
} catch (MediaException me)<br />
{<br />
}</p>
<p>// now take a picture<br />
try {<br />
byte[] pngImage =<br />
vc.getSnapshot(null);</p>
<p>// do something with the image ...<br />
} catch (MediaException me)<br />
{<br />
}</p>

	Tags: <a href="http://zhangv.com/archives/tag/j2me" title="j2me" rel="tag">j2me</a><br />
]]></content:encoded>
			<wfw:commentRss>http://zhangv.com/archives/144/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>怎样使用MMAPI录音</title>
		<link>http://zhangv.com/archives/143</link>
		<comments>http://zhangv.com/archives/143#comments</comments>
		<pubDate>Sun, 02 Mar 2008 06:58:24 +0000</pubDate>
		<dc:creator>zhangv</dc:creator>
				<category><![CDATA[非技术(non-tech)]]></category>
		<category><![CDATA[j2me]]></category>

		<guid isPermaLink="false">http://218.22.170.60/zhangv/wordpress/?p=408</guid>
		<description><![CDATA[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");
  [...]]]></description>
			<content:encoded><![CDATA[<pre>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) { }</pre>

	Tags: <a href="http://zhangv.com/archives/tag/j2me" title="j2me" rel="tag">j2me</a><br />
]]></content:encoded>
			<wfw:commentRss>http://zhangv.com/archives/143/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MoFire</title>
		<link>http://zhangv.com/mofire</link>
		<comments>http://zhangv.com/mofire#comments</comments>
		<pubDate>Wed, 27 Feb 2008 10:10:22 +0000</pubDate>
		<dc:creator>zhangv</dc:creator>
				<category><![CDATA[非技术(non-tech)]]></category>
		<category><![CDATA[j2me]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[mofire]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://218.22.170.60/zhangv/wordpress/?page_id=224</guid>
		<description><![CDATA[
最新版本(latest version): 0.6.1 download
Source code:
http://code.google.com/p/mofire/
http://sourceforge.net/projects/mofire/
Download and try:
http://mosh.nokia.com/content/4897555AA597E7C5E040050A45306893
手机上的wordpress客户端(jme)
1.支持拍照并发布带图片附件的日志
2.可配置多个blog
3.可保存日志到手机
4.支持从本地载入图片并发布到blog
5.支持分类，标签，使用MetaWeblog API

类图:

mofire-uml-0.1
FAQs:
What is mofire?
It's a blogging client on your mobile phone.
 What blogging application mofire supports?
Initially, this is for my own wordpress blog. Theoretically, it supports all the blog application that support metaweblog API.
Why “mofire"?
"mo" is my prefix, means "nothing", "fire" is to after my favorite blogging client - [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://zhangv.com/wordpress/wp-content/uploads/mofire-logo.png"><img class="alignnone size-medium wp-image-295" title="mofire-logo" src="http://zhangv.com/wordpress/wp-content/uploads/mofire-logo-300x256.png" alt="" width="105" height="91" /></a></p>
<p>最新版本(latest version): 0.6.1 <a href="http://zhangv.com/MoFire.jar">download</a></p>
<p>Source code:<br />
http://code.google.com/p/mofire/<br />
http://sourceforge.net/projects/mofire/</p>
<p>Download and try:<br />
http://mosh.nokia.com/content/4897555AA597E7C5E040050A45306893</p>
<p>手机上的wordpress客户端(jme)</p>
<p>1.支持拍照并发布带图片附件的日志<br />
2.可配置多个blog<br />
3.可保存日志到手机<br />
4.支持从本地载入图片并发布到blog<br />
5.支持分类，标签，使用MetaWeblog API</p>
<p><a href="http://zhangv.com/wordpress/wp-content/uploads/scr000003.jpg"><img class="alignnone size-medium wp-image-303" title="mofire-screenshot" src="http://zhangv.com/wordpress/wp-content/uploads/scr000003-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>类图:</p>
<p><a href="http://zhangv.com/wordpress/wp-content/uploads/mofire-class.jpg"><img class="alignnone size-medium wp-image-299" title="mofire-class" src="http://zhangv.com/wordpress/wp-content/uploads/mofire-class-300x219.jpg" alt="" width="300" height="219" /></a><a href="http://zhangv.com/wordpress/wp-content/uploads/mofire.uml"><br />
mofire-uml-0.1</a></p>
<h2><strong>FAQs:</strong></h2>
<p><strong>What is mofire?</strong><br />
It's a blogging client on your mobile phone.</p>
<p><strong> What blogging application mofire supports?</strong><br />
Initially, this is for my own wordpress blog. Theoretically, it supports all the blog application that support metaweblog API.</p>
<p><strong>Why “mofire"?</strong><br />
"mo" is my prefix, means "nothing", "fire" is to after my favorite blogging client - scribefire.</p>
<p><strong>How to setup a blog configuration?</strong><br />
First create a "setting", input the field:<br />
Name: identify the setting, you can have multiple settings<br />
URL: the xmlrpc url of your blog server. eg, mine is: http://zhangv.com/xmlrpc.php<br />
User: the user of blog server<br />
Password: the password of user<br />
set as default: if set, when you start mofire, it will use this setting and directly go to post form. If not, you have to choose the setting to use.<br />
After all the above, [validate setting] to test if it is ok. Recommend you to validate it every time setting is changed.</p>
<p><strong>How to post an blog?</strong><br />
First, make sure to [use] a setting in the setting list.<br />
Input the title, select a category, fill the tags(split by comma or space).<br />
Then [edit content] to open the content editing form, and write your stuff, then [post].</p>
<p><strong>How to save an blog in the mobile phone?</strong><br />
After input all the stuff, if you don't have a working connection, you can choose to [save] it to your mobile phone and post it when you go to starbuck. Then choose [drafts], and select the entry and post it.</p>
<p><strong>How to attach a photo from phone gallary?</strong><br />
Still working on, will implement later. JavaME seems cannot handle picture of size 100kb around.</p>
<p><strong>How to use the camera and post the photo just shot?</strong><br />
Select [camera], and [capture] the scene. Then you can see the shrink photo displayed in the post form, you can remove it if not good. Then post it.<br />
NOTE: make sure you have the privilege to insert an image in your blog entry.</p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input name="cmd" type="hidden" value="_s-xclick" />
<input name="hosted_button_id" type="hidden" value="4058833" />
<input alt="PayPal - The safer, easier way to pay online!" name="submit" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" type="image" /> </form>

	Tags: <a href="http://zhangv.com/archives/tag/j2me" title="j2me" rel="tag">j2me</a>, <a href="http://zhangv.com/archives/tag/mobile" title="mobile" rel="tag">mobile</a>, <a href="http://zhangv.com/archives/tag/mofire" title="mofire" rel="tag">mofire</a>, <a href="http://zhangv.com/archives/tag/wordpress" title="wordpress" rel="tag">wordpress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://zhangv.com/mofire/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>使用antenna时候的问题</title>
		<link>http://zhangv.com/archives/120</link>
		<comments>http://zhangv.com/archives/120#comments</comments>
		<pubDate>Sat, 02 Feb 2008 10:33:46 +0000</pubDate>
		<dc:creator>zhangv</dc:creator>
				<category><![CDATA[技术(Tech)]]></category>
		<category><![CDATA[ant]]></category>
		<category><![CDATA[antenna]]></category>
		<category><![CDATA[j2me]]></category>
		<category><![CDATA[mofire]]></category>

		<guid isPermaLink="false">http://218.22.170.60/zhangv/wordpress/?p=166</guid>
		<description><![CDATA[编译时找不到List.deleteAll这个方法，因为默认的的antenna使用cldc1.0。而这个deleteall是1.1的方法，解决方法是覆盖默认的cldc版本
&#60;property name="wtk.cldc.version" value="1.1"/&#62;
Antenna是用来构建j2me项目的ant任务 扩展。让整个构建过程变的很简单和易于管理。
附我使用的构建脚本供参考：
&#60;?xml version="1.0"?&#62;
&#60;project name="MoFire" default="build" basedir="."&#62;
&#60;!-- Define the Wireless Toolkit home directory. Needed by the tasks. --&#62;
&#60;property name="wtk.home" value="D:\development\WTK2.5.2"/&#62;
&#60;property name="wtk.cldc.version" value="1.1"/&#62;
&#60;property name="wtk.midp.version" value="2.0"/&#62;
&#60;property name="wtk.proguard.home" value="D:\development\workspaceME\lib\proguard4.1\"/&#62;
&#60;!-- Define some additional properties for this project. Not required. --&#62;
&#60;property name="midlet.name" value="${ant.project.name}"/&#62;
&#60;property name="midlet.home" value="."/&#62;
&#60;property name="midlet.vendor" value="MoDoFo"/&#62;
&#60;property name="midlet.version" value="0.0.1"/&#62;
&#60;!-- Define the tasks. --&#62;
&#60;taskdef resource="antenna.properties" classpath="lib/antenna-bin-1.0.0.jar"/&#62;
&#60;target name="clean"&#62;
&#60;delete failonerror="false" dir="classes"/&#62;
&#60;/target&#62;
&#60;target name="dist" [...]]]></description>
			<content:encoded><![CDATA[<p>编译时找不到List.deleteAll这个方法，因为默认的的antenna使用cldc1.0。而这个deleteall是1.1的方法，解决方法是覆盖默认的cldc版本</p>
<p>&lt;property name="wtk.cldc.version" value="1.1"/&gt;</p>
<p>Antenna是用来构建j2me项目的ant任务 扩展。让整个构建过程变的很简单和易于管理。</p>
<p>附我使用的构建脚本供参考：</p>
<p>&lt;?xml version="1.0"?&gt;</p>
<p>&lt;project name="MoFire" default="build" basedir="."&gt;</p>
<p>&lt;!-- Define the Wireless Toolkit home directory. Needed by the tasks. --&gt;</p>
<p>&lt;property name="wtk.home" value="D:\development\WTK2.5.2"/&gt;<br />
&lt;property name="wtk.cldc.version" value="1.1"/&gt;<br />
&lt;property name="wtk.midp.version" value="2.0"/&gt;<br />
&lt;property name="wtk.proguard.home" value="D:\development\workspaceME\lib\proguard4.1\"/&gt;</p>
<p>&lt;!-- Define some additional properties for this project. Not required. --&gt;</p>
<p>&lt;property name="midlet.name" value="${ant.project.name}"/&gt;<br />
&lt;property name="midlet.home" value="."/&gt;<br />
&lt;property name="midlet.vendor" value="MoDoFo"/&gt;<br />
&lt;property name="midlet.version" value="0.0.1"/&gt;<br />
&lt;!-- Define the tasks. --&gt;</p>
<p>&lt;taskdef resource="antenna.properties" classpath="lib/antenna-bin-1.0.0.jar"/&gt;</p>
<p>&lt;target name="clean"&gt;<br />
&lt;delete failonerror="false" dir="classes"/&gt;<br />
&lt;/target&gt;</p>
<p>&lt;target name="dist" depends="build"&gt;<br />
&lt;mkdir dir="dist/${midlet.name}-${midlet.version}" /&gt;<br />
&lt;property name="distfolder" value="dist/${midlet.name}-${midlet.version}"/&gt;<br />
&lt;zip destfile="${distfolder}/${midlet.name}-${midlet.version}-src.zip"&gt;<br />
&lt;fileset dir="src" includes="**/*.*" /&gt;<br />
&lt;fileset dir="res" includes="**/*.*" /&gt;<br />
&lt;/zip&gt;<br />
&lt;copy file="${midlet.name}.jad" todir="${distfolder}" /&gt;<br />
&lt;copy file="${midlet.name}.jar" todir="${distfolder}" /&gt;<br />
&lt;copy file="README.txt" todir="${distfolder}" /&gt;</p>
<p>&lt;wtkrun jadfile="${distfolder}/${midlet.name}.jad" device="DefaultColorPhone" wait="true"/&gt;<br />
&lt;/target&gt;</p>
<p>&lt;target name="build"&gt;</p>
<p>&lt;!-- Make a JAD file from scratch, don't copy the original one. --&gt;</p>
<p>&lt;wtkjad jadfile="${midlet.name}.jad"<br />
name="${midlet.name}"<br />
vendor="${midlet.vendor}"<br />
version="${midlet.version}" &gt;</p>
<p>&lt;midlet name="MoFire"<br />
icon="/logo.png"<br />
class="com.modofo.mofire.MoFire"/&gt;<br />
&lt;/wtkjad&gt;</p>
<p>&lt;mkdir dir="classes"/&gt;</p>
<p>&lt;!-- Compile everything, but don't preverify (yet). --&gt;</p>
<p>&lt;wtkbuild srcdir="${midlet.home}/src"<br />
destdir="classes"<br />
preverify="false"/&gt;</p>
<p>&lt;!-- Package everything. Most of the necessary information is<br />
contained in the JAD file. Also preverify the result this<br />
time. To obfuscate everything, set the corresponding<br />
parameter to "true" (requires RetroGuard or ProGuard). The<br />
version parameter increments the MIDlet-Version by one. --&gt;</p>
<p>&lt;wtkpackage jarfile="${midlet.name}.jar"<br />
jadfile="${midlet.name}.jad"<br />
obfuscate="false"<br />
autoversion="true"&gt;</p>
<p>&lt;!-- Package our newly compiled classes and the<br />
resources from the WTK's demo application. --&gt;</p>
<p>&lt;fileset dir="classes"/&gt;<br />
&lt;fileset dir="${midlet.home}/res"/&gt;</p>
<p>&lt;/wtkpackage&gt;</p>
<p>&lt;!-- Obfuscate. --&gt;<br />
&lt;!-- Not needed<br />
&lt;wtkobfuscate jarfile="${midlet.name}.jar"<br />
jadfile="${midlet.name}.jad"/&gt;<br />
--&gt;<br />
&lt;!-- Preverify things, this time separately to test the<br />
corresponding task. --&gt;</p>
<p>&lt;wtkpreverify jarfile="${midlet.name}.jar"<br />
jadfile="${midlet.name}.jad"/&gt;</p>
<p>&lt;!-- Convert the JAR file into a MIDP for PalmOS PRC file. --&gt;<br />
&lt;!-- Not supported in wtk anymore - Zhangv<br />
&lt;wtkmakeprc jadfile="${midlet.name}.jad"<br />
prcfile="${midlet.name}.prc"/&gt;<br />
--&gt;<br />
&lt;!-- Start the MIDlet suite --&gt;<br />
&lt;!-- Not need<br />
&lt;wtkrun jadfile="${midlet.name}.jad" device="DefaultColorPhone" wait="true"/&gt;<br />
--&gt;<br />
&lt;/target&gt;<br />
&lt;/project&gt;</p>

	Tags: <a href="http://zhangv.com/archives/tag/ant" title="ant" rel="tag">ant</a>, <a href="http://zhangv.com/archives/tag/antenna" title="antenna" rel="tag">antenna</a>, <a href="http://zhangv.com/archives/tag/j2me" title="j2me" rel="tag">j2me</a>, <a href="http://zhangv.com/archives/tag/mofire" title="mofire" rel="tag">mofire</a><br />
]]></content:encoded>
			<wfw:commentRss>http://zhangv.com/archives/120/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

