gpt4 book ai didi

android - SoundPool 停止功能不停止

转载 作者:太空宇宙 更新时间:2023-11-03 11:59:56 24 4
gpt4 key购买 nike

我正在制作一款应用,您可以在其中选择 1 到 4 种不同的声音并同时播放它们。一切正常,直到我想停止声音,功能停止同时仅适用于一种声音,这是代码(仅适用于 soundpool)

sound = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
s1 = sound.load(Main.this, R.raw.mosq1, 1);
s2 = sound.load(Main.this, R.raw.mosq2, 1);
s3 = sound.load(Main.this, R.raw.mosq3, 1);
s4 = sound.load(Main.this, R.raw.mosq4, 1);
.
.
.
.
case R.id.play:
if (l1==true){sound.play(s1, 1, 1, 0, rep, 1); if(vib==true) wibracja.vibrate(4500);}
if (l2==true){sound.play(s2, 1, 1, 0, rep, 1); if(vib==true) wibracja.vibrate(6500);}
if (l3==true){sound.play(s3, 1, 1, 0, rep, 1); if(vib==true) wibracja.vibrate(2500);}
if (l4==true){sound.play(s4, 1, 1, 0, rep, 1); if(vib==true) wibracja.vibrate(4500);}
break;
case R.id.stop:
sound.stop(s1);
sound.stop(s2);
sound.stop(s3);
sound.stop(s4);
wibracja.cancel();
break;

如何正确使用停止功能?感谢帮助

最佳答案

对于那些使用 soundpool 的人来说,这是一个常见的问题第一次。如果您仔细查看 soundpool 的文档,播放使用参​​数“soundID”,而停止使用参数“streamID”。很容易忽略这一点,并像您的代码一样对这两个命令使用从加载函数返回的 soundID。我什至见过 android 教程示例弄错了。而是使用这些命令:

s1 = sound.load(Main.this, R.raw.mosq1, 1);  
if (l1==true){p1=sound.play(s1, 1, 1, 0, rep, 1);
sound.stop(p1);// NOT s1

关于android - SoundPool 停止功能不停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12220384/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com