SoundPool 声音没有变化

发布于 2024-09-16 23:10:40 字数 1048 浏览 4 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绾颜 2024-09-23 23:10:40

这是 play() 语法:

public final int  play  (int soundID, float leftVolume, float rightVolume, int priority, int loop, float rate)

那么不应该是:

 sounds.play(soundmap.get(UFO),0.8F,0.8F,1,-1, 1);

让声音永远循环吗?

编辑:阅读问题有点快,但是如果您使用此播放功能,它会循环播放吗?

Here is the play() syntax:

public final int  play  (int soundID, float leftVolume, float rightVolume, int priority, int loop, float rate)

So shouldn't it be:

 sounds.play(soundmap.get(UFO),0.8F,0.8F,1,-1, 1);

to make the sound loop forever?

Edit: Read the question a bit to fast but if you use this play function, does it loop?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文