的Soundpool样品未准备好样品、Soundpool

2023-09-13 00:22:50 作者:习惯后的伤痛

我有,我想在我的游戏中使用,目前我加载在的onCreate()游戏中的每一个活动的声音.wav文件。

I have a .wav file that I'd like to use across my game, currently I am loading the sound in onCreate() of each activity in the game.

 soundCount = soundpool.load(this,R.raw.count, 1);

在活动开始的声音将被播放。

The sound will be played once the activity starts.

  soundpool.play(soundCount, 0.9f, 0.9f, 1, -1, 1f);

但问题是,有时我会打的误差样本x未准备好。 是否有可能在开始游戏加载.wav文件一次,并保持它在内存中,以后使用它在整个游戏?或者是有可能要等待1-2秒的声音加载完成?

Problem is at times I will hit the error "sample x not ready". Is it possible to load the .wav file once upon starting the game and keep it in memory and use it later across the game? Or is it possible to wait for 1-2 seconds for the sound to load finish?

推荐答案

您需要等待它经由 SoundPool.setOnLoadCompleteListener 添加一个监听器完成。

You'll need to wait for it to finish by adding a listener via SoundPool.setOnLoadCompleteListener.