0

Hi I'm working on an android Java app where I need to play three different sounds with soundpool at the same time using three different buttons.**code in picture **. I loaded sounds into three buttons but when I click all three at time no sound is played. But it works when i click two buttons. Is there any way to do this.

4

1 回答 1

0

使用.setMaxStreams(int maxStreams)内部SoundPool.Builder()方法。由于这适用于 api 21 或更高版本,因此您需要设置条件。IE

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // lollipop is constant for api 21
        AudioAttributes audioAttributes = new AudioAttributes.Builder() // using instance of audio attributes
                .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) // different usage types, press CTRL+B & we get to it's declaration, and we see the description of usage types.
                .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) 
                .build();
    soundPool = new SoundPool.Builder()
        .setMaxStreams(10) //  Sets the maximum of number of simultaneous streams 
                            // that can be played simultaneously.
        .setAudioAttributes(audioAttributes)
        .build();
    }
       else{
         soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
    }
于 2018-05-17T03:46:54.323 回答