利用J2ME媒体库播放音频的最佳方式是什么?例如,我应该使用MMAPI,还是应该只使用Midlet的platformRequest(String s)方法?
发布于 2009-01-26 14:28:00
下面的代码应该适用于90-95%的支持JSR-135的手机。对所有不同的方法调用进行排序是实现可移植性的关键。这是为您的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;发布于 2009-01-26 14:03:25
你说的最好是什么意思?最高质量?最佳用户体验?大多数标准兼容?
基本上(这不是我知道的最好的答案),这取决于平台-这是J2ME熟悉的主题-因为实现可能有很大的不同,而且MMAPI通常利用一些本机媒体播放器软件/硬件。在BlackBerry上,MMAPI运行得很好,但有一些小问题。
我的建议是在MMAPI运行良好的地方使用它-它将为您提供最便携的应用程序。针对您的特定目标设备集进行试验或浏览开发人员主板,以了解它在您想要支持的手持设备上的运行情况。
发布于 2009-01-26 14:34:14
在某些设备上,使用平台请求将导致应用程序关闭,而在其他设备上,某些平台请求将导致设备崩溃(某些设备上的HTTP除外)。
因此,您可能需要使用这两种方法,根据设备测试来选择使用哪种方法。
https://stackoverflow.com/questions/473809
复制相似问题