mmapi 在j2me polish中的应用

近日工作中,要在j2me polish项目里实现mmapi, 其中的视频的实现在j2me polish与一般j2me项目里是不同的,弄了一天都不能播放。后来在网上问了一个高手才知道,下面我们看看Video Play 在polish中的实现:

j2me里实现mmapi的基本解释我不多说了,不了解的可以参考 [url]http://hi.baidu.com/cobalt/blog/item/fdb457c25e4c0237e4dd3b71.html[/url] 里边讲得很详细的,我们主要看看实现mmapi video的播放的代码:

java 代码:

[code]
try {
InputStream is = getClass().getResourceAsStream("/3.mpg");
Player p = Manager.createPlayer(is, "video/mpeg");
p.realize();
// Grab the video control and set it to the current display.
VideoControl vc = (VideoControl)p.getControl("VideoControl");
if (vc != null) {
Form form = new Form("Video form");
form.append((Item)vc.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null));
display.setCurrent(form);
}
p.start();
} catch (IOException ioe) {
} catch (MediaException me) { }

[/code]

当我在j2me polish工程中按这样实现的时候,老是出现下边的异常:

[code]
Generic/DefaultColorPhone: startApp threw an Exception
Generic/DefaultColorPhone: java.lang.ClassCastException
Generic/DefaultColorPhone: java.lang.ClassCastException
Generic/DefaultColorPhone: at com.protel.MM.UI.MMMidlet.startApp(+224)
Generic/DefaultColorPhone: [javac] C:\Documents and Settings\winxp\Desktop\mmapi\source\src\com\protel\MM\UI\MMMidlet.java:57: form.append((Item)vc.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null));
Generic/DefaultColorPhone: at javax.microedition.midlet.MIDletProxy.startApp(+7)
Generic/DefaultColorPhone: at com.sun.midp.midlet.Scheduler.schedule(+270)
Generic/DefaultColorPhone: at com.sun.midp.main.Main.runLocalClass(+28)
Generic/DefaultColorPhone: at com.sun.midp.main.Main.main(+116)
[/code]

原来在j2me polish应用中所有的Screen或Item都经过preproceses(预处理),故所有新创建或返回的Screen/Item都默认是de.enough.polish.ui.*里边的,
所以直接调用上边的代码时会发生类型转换异常。所以要在j2me polish项目中正常播放video要直接引用javax.microedition.lcdui.*
的类,修改后的代码如下:

[code]
try {
System.out.println("~~~~~~~~~~"+getClass().getResourceAsStream("/3.mpg"));
InputStream is = getClass().getResourceAsStream("/3.mpg");
Player p = Manager.createPlayer(is, "video/mpeg");
p.realize();
// Grab the video control and set it to the current display.
VideoControl vc = (VideoControl)p.getControl("VideoControl");
if (vc != null) {
javax.microedition.lcdui.Form form = new javax.microedition.lcdui.Form("Video form");
javax.microedition.lcdui.Item videoItem = (javax.microedition.lcdui.Item)vc.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null);
form.append(videoItem);

display.setCurrent(form);
}
p.start();
} catch (IOException ioe) {
} catch (MediaException me) { }
[/code]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值