zoukankan      html  css  js  c++  java
  • [J2ME]Nokia播放音乐时发生MediaException的解决办法

     

     [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

    解决

    原因是,Player::setMediaTime函数在Nokia 7610上不支持!

    修正为以下代码后,真机测试通过。具体的应用文档参见:《[J2ME]手机也可以玩播客(Podcast)! Geek客说明,源代码下载https://files.cnblogs.com/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();

     

    希望这个报告对你有参考价值。也希望你能够告诉我-18代表着什么。

     

    郑昀@ultrapower

    产品名称

    产品版本

    Keyword: Mobile Media 媒体播放 j2me midp MediaException

    iPodderX

    Mobile

    0.0.1 BETA

     

  • 相关阅读:
    日志到底该如何打印?
    消息摘要(MessageDigest)
    URL编码及解码原理
    AES简介
    MySQL中整型长度的意义
    keytool生成密钥
    证书类型及秘钥库
    Base64编码及解码原理
    Holistically-Nested Edge Detection 论文总结
    全新bili主题
  • 原文地址:https://www.cnblogs.com/zhengyun_ustc/p/NokiaMediaException18.html
Copyright © 2011-2022 走看看