2

我在方法中写了这段代码onCreate(),但是什么都没播放!

   SoundPool mSound = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
   AudioManager mAudioManager = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE);          

   int soundID = mSound.load(this, R.raw.sound1, 1);

   int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); 
   mSound.play(soundID, streamVolume, streamVolume, 1, 0, 1f);

问题 #1:我的代码有问题吗?我做错了吗?

如果不,

问题 #2:我的声音是.amr文件。支持SoundPool吗?支持的类型有哪些?

4

2 回答 2

3

一切都很好,但是您应该在加载后和播放前等待一段时间。加载需要一些时间。您可以在“OnLoadCompleteListener”的帮助下检查声音是否已加载。

于 2012-01-03T19:29:08.287 回答
2

代码片段看起来不错。有关受支持格式的列表,请参阅文档。看来您必须尝试改用 .mp3 或 .ogg 或 .wav。根据文档支持 AMR 编解码器,但文件必须为 .3gp 格式。

于 2011-07-09T12:31:25.167 回答