[J2ME]Nokia播放音乐时发生MediaException的解决办法
现象
在Nokia7610上播放音乐时遇到了-18的MediaException错误!
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,他04年11月报告过这个错误:
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
|