BoomPsy
BoomPsy

Reputation: 1

Android multi_touch listener

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.

Upvotes: 0

Views: 56

Answers (1)

dvlpr
dvlpr

Reputation: 1

Use .setMaxStreams(int maxStreams) inside SoundPool.Builder() method. As this works on api 21 or higher, so you need to set the condition. i.e.

    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);
    }

Upvotes: 0

Related Questions