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

news/2024/7/2 1:12:36

[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

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 





http://www.niftyadmin.cn/n/3649664.html

相关文章

如何在CentOS 7上为生产设置Node.js应用程序

介绍 (Introduction) Node.js is an open source Javascript runtime environment for easily building server-side and networking applications. The platform runs on Linux, OS X, FreeBSD, and Windows, and its applications are written in JavaScript. Node.js applic…

[j2me]手机也可以玩播客(Podcasting On Mobile)!开源开发说明

[J2ME] 手机也可以玩播客(Podcast)! Geek说明摘要:本文档给出iPodderX on Mobile 之Kjava版本的Geek说明。第1章 简单描述这个iPodderX的功能和特别之处。第2章 给出了 这个iPodderX的下载资源。我的IPodderX on Mobile资源:1:《[…

4G时代:手机不仅是电话

本报记者 朱伟 张晓鸣题记美国东部时间6月4日。上午7点不到,全美第三大移动运营商Sprint公司位于曼哈顿西23街Flatiron大厦底层的营业厅门前,已经排起了一条300多人的等候长龙。热情的发烧友们此时表现得很安静,尽管他们即将见证一个历史时刻…

hm-geosphere!也许算是web2.0的一个创意了

http://hm-geosphere.sourceforge.net/在你的页面上加入下面这样的代码&#xff0c;你就可以得到我的blog左边那个能用鼠标转动的地球的效果&#xff0c;可以添加你的坐标&#xff0c;这也算是一个web2.0的创意了。hm-geosphere盛装演示<script language"JavaScript&qu…

Android项目实战系列—基于博学谷(一)项目综述

一、项目分析 1、项目名称 WordPress建站APP 2、项目概述 WordPress建站是一个学习博客建站技术的APP&#xff0c;主要讲述WordPress建站过程。APP基于黑马程序员的博学谷自学助手项目进行开发和创新。是移动高级开发课程的学生自主设计项目。博客内容会讲述APP的原型设计、…

ldflags_使用ldflags设置Go应用程序的版本信息

ldflags介绍 (Introduction) When deploying applications into a production environment, building binaries with version information and other metadata will improve your monitoring, logging, and debugging processes by adding identifying information to help tra…

[J2ME]手机看交通监视器实时录像 实现说明

[J2ME] 手机看交通监视器实时录像实现说明摘要&#xff1a;本文档给出Mobile TrafficCam Viewer的实现说明。第1章 简单描述Mobile TrafficCam Viewer的功能和特别之处。第2章 给出了 Mobile TrafficCam Viewer的下载资源。1背景、功能和特别之处摘要&#xff1a;本章 简单描述…

Android项目实战系列—基于博学谷(二)界面设计

一、原型设计介绍 百度百科&#xff1a;原型设计是交互设计师与PD、PM、网站开发工程师沟通的最好工具。而该块的设计在原则上必须是交互设计师的产物&#xff0c;交互设计以用户为中心的理念会贯穿整个产品。利用交互设计师专业的眼光与经验直接导致该产品的可用性。产品原型…