SoundPool 声音没有变化
我有一个 soundpool 对象和几个声音,但是一旦创建,我就无法以任何方式更改声音播放,例如循环次数、音量、停止等。
声明代码:
public SoundPool sounds;
public HashMap<Integer, Integer> soundmap = new HashMap<Integer, Integer>();
static final public int UFO=3;
static final public int PlayerDeath=3;
static final public int InvaderDeath=2;
static final public int PlayerFire=1;
声音分配代码:
sounds = new SoundPool(10,AudioManager.STREAM_MUSIC,0);
soundmap.put(PlayerDeath,sounds.load(getContext(), R.raw.explosion, 1));
soundmap.put(InvaderDeath,sounds.load(getContext(), R.raw.invaderkilled, 1));
soundmap.put(PlayerFire,sounds.load(getContext(),R.raw.shoot, 1));
soundmap.put(UFO,sounds.load(getContext(),R.raw.ufo, 1));
开始/停止代码:
public void PlayUFOMusic()
{
sounds.play(soundmap.get(UFO),0.8F,0.8F,1,2000,1);
}
public void StopUFOMusic()
{
sounds.stop(soundmap.get(UFO));
}
我知道这些正在调用函数,但无论如何都不会导致它发生变化。我也尝试过 setLoop、setVolume、pause 和 unload,但这些都不起作用。
有什么想法吗?
I have a soundpool object and several sounds, but once created I can't change the sounds playback in anyway, such as number of loops, volume, stopping, etc.
Declaration code:
public SoundPool sounds;
public HashMap<Integer, Integer> soundmap = new HashMap<Integer, Integer>();
static final public int UFO=3;
static final public int PlayerDeath=3;
static final public int InvaderDeath=2;
static final public int PlayerFire=1;
Sound assignment code:
sounds = new SoundPool(10,AudioManager.STREAM_MUSIC,0);
soundmap.put(PlayerDeath,sounds.load(getContext(), R.raw.explosion, 1));
soundmap.put(InvaderDeath,sounds.load(getContext(), R.raw.invaderkilled, 1));
soundmap.put(PlayerFire,sounds.load(getContext(),R.raw.shoot, 1));
soundmap.put(UFO,sounds.load(getContext(),R.raw.ufo, 1));
Start/stop code:
public void PlayUFOMusic()
{
sounds.play(soundmap.get(UFO),0.8F,0.8F,1,2000,1);
}
public void StopUFOMusic()
{
sounds.stop(soundmap.get(UFO));
}
I know these functions are being called but nothing will cause it change in anyway. I've also tried setLoop, setVolume, pause and unload, none of these worked either.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 play() 语法:
那么不应该是:
让声音永远循环吗?
编辑:阅读问题有点快,但是如果您使用此播放功能,它会循环播放吗?
Here is the play() syntax:
So shouldn't it be:
to make the sound loop forever?
Edit: Read the question a bit to fast but if you use this play function, does it loop?