Par*_*ius 5 audio mmapi java-me media-player
使用J2ME Media库的音频播放的最佳方法是什么?例如,我应该使用MMAPI还是应该使用Midlet的platformRequest(String s)方法?
以下代码适用于支持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;
Run Code Online (Sandbox Code Playgroud)
最好,你是什么意思?最好的质量?最好的用户体验?符合大多数标准?
基本上(这不是我所知道的最好的答案),它取决于平台 - 这是 J2ME 的一个熟悉的主题 - 因为实现可能有很大差异,并且 MMAPI 通常利用一些本机媒体播放器软件/硬件。在 BlackBerry 上,MMAPI 运行良好,但有一些怪癖。
我的建议是在运行良好的地方使用 MMAPI - 它将为您提供最可移植的应用程序。试验或浏览特定目标设备集的开发板,看看它在您想要支持的手机上的运行情况如何。
| 归档时间: |
|
| 查看次数: |
12272 次 |
| 最近记录: |