[J2ME]Nokia播放音乐时发生MediaException的解决办法

本文介绍了一种在Nokia7610上使用J2ME播放音乐时遇到MediaException(-18)的问题及解决方案。通过调整代码实现成功播放。
<iframe align="center" marginwidth="0" marginheight="0" src="http://www.zealware.com/csdnblog336280.html" frameborder="0" width="336" scrolling="no" height="280"></iframe>

[J2ME]Nokia播放音乐时发生MediaException的解决办法

现象

Nokia7610上播放音乐时遇到了-18MediaException错误!

J2ME中播放音乐资源的代码很容易找,我是直接从这篇比较经典的《熟练使用J2ME在实际开发中的可选包MMAPI》中复制的代码,

心想,这总不会有错吧?

播放媒体文件流,真机测试发生异常的代码

Player p = Manager.createPlayer(m_isInputImage,"audio/amr");

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

这段代码在Nokia开发工具包的S60系列模拟器上顺利通过!

但是,不幸的事情发生了,在真机测试中,Nokia7610弹出一个错误:

javax.microedition.media.MediaException: -18

这下,在网上根本找不到-18这个错误号到底代表什么。

和我有类似情况的还有houhou,他0411月报告过这个错误:

http://www.cnjm.net/cgi-bin/lbcjm/topic.cgi?forum=5&topic=4582

解决

不知道错误原因,但是按照houhou的代码修正后,问题消失了!

发信问了houhou,他也说不知道原因,反正最终解决了这个问题,并给我了测试源代码,这里深深地感谢houhou

修正为以下代码后,真机测试通过。具体的应用文档参见:《[J2ME]手机也可以玩播客(Podcast)! Geek客说明,源代码下载http://www.cnblogs.com/Files/zhengyun_ustc/toodouPodcastMidlet.rar

播放媒体文件流,能测试通过的代码

m_player = Manager.createPlayer(m_isInputImage,

"audio/amr");

// realize the player

m_player.realize();

System.out.println("Got player realize!");

// Guarantee that the player can start with the smallest latency.

m_player.prefetch();

System.out.println("Got player prefetch!");

// Grab volume control for the player.

// Set Volume to max.

m_volume = (VolumeControl)

m_player.getControl("VolumeControl");

if (m_volume != null)

m_volume.setLevel(m_nVolume);

System.out.println("Got VolumeControl!");

m_player.start();

希望这个报告对你有参考价值。

郑昀@ultrapower

产品名称

产品版本

Keyword: Mobile Media 媒体播放 j2me midp MediaException

iPodderX

Mobile

0.0.1 BETA




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值