【问题标题】:SoundPool stop function not stoppingSoundPool 停止功能未停止
【发布时间】:2012-08-31 17:58:02
【问题描述】:

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

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;

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

【问题讨论】:

    标签: android soundpool


    【解决方案1】:

    对于使用 soundpool 的用户来说,这是一个常见问题 第一次。如果您仔细查看 soundpool 的文档,play 使用参数“soundID”,而 stop 使用参数“streamID”。很容易忽略这一点,并使用从 load 函数返回的 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-09
      • 2012-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多