【问题标题】:Playing Audio with J2ME使用 J2ME 播放音频
【发布时间】:2009-01-23 17:38:45
【问题描述】:

使用 J2ME 媒体库播放音频的最佳方式是什么? 例如,我应该使用 MMAPI 还是只使用 Midlet 的 platformRequest(String s) 方法?

【问题讨论】:

  • 这真的取决于你想做什么......你应该更具体地了解你所追求的。如果你想播放 MP3,这很容易。如果您想通过互联网流式传输音频,那几乎是不可能的。

标签: audio java-me media-player mmapi


【解决方案1】:

以下代码应该适用于支持 JSR-135 的 90-95% 的手机。所有各种方法调用的排序是可移植的关键。这适用于 JAR 本地的声音。任何流式音频将完全是另一个问题:)

// loads the InputStream for the sound
InputStream inputStream = this.getClass().getResourceAsStream( musicFile );

// create the standard Player
musicPlayer = Manager.createPlayer( inputStream, musicEncoding );
musicPlayer.prefetch();

// add player listener to access sound events
musicPlayer.addPlayerListener( this );

if( loopMusic )
{    
    // use the loop count method for infinite looping
    musicPlayer.setLoopCount( -1 );
}

// The set occurs twice to prevent sound spikes at the very 
// beginning of the sound.
VolumeControl volumeControl = 
   (VolumeControl) musicPlayer.getControl( "VolumeControl" );
volumeControl.setLevel( curVolume );

// finally start the piece of music
musicPlayer.start();

// set the volume once more
volumeControl = (VolumeControl) musicPlayer.getControl( "VolumeControl" );
volumeControl.setLevel( curVolume );

// finally, delete the input stream to save on resources
inputStream.close();
inputStream = null;

【讨论】:

    【解决方案2】:

    最好,你是什么意思?最好的质量?最佳用户体验?最符合标准?

    基本上(这不是我所知道的最佳答案),它取决于平台 - 这是 J2ME 熟悉的主题 - 因为实现可能有很大差异,并且 MMAPI 通常利用一些本机媒体播放器软件/硬件。在 BlackBerry 上,MMAPI 运行良好,但有一些怪癖。

    我的建议是在运行良好的地方使用 MMAPI - 它会为您提供最便携的应用程序。试验或浏览您的特定目标设备集的开发板,看看它在您想要支持的手机上的运行情况。

    【讨论】:

      【解决方案3】:

      在某些设备上使用平台请求会导致您的应用程序关闭,而在其他设备上某些平台请求会导致设备崩溃(某些设备上的 HTTP URL 除外)。

      因此您可能需要同时使用这两种方法,根据设备测试选择使用哪一种。

      【讨论】:

        【解决方案4】:

        本地音频(在 Jar 文件中)更容易支持,如上面 Shane 的回复中所述。对于网络上的内容,随着服务器连接问题、手机内存等许多因素的影响,它变得更加困难。如果您需要支持大量手机,那么建议您使用 2-3 种实现技术并相应地使用。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-01-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-09-14
          相关资源
          最近更新 更多