jeudi 11 avril 2019

how to play one sound onclick but randomize what other sounds might be by choosing from array

brand spanking new to android / java development and trying to learn.

My problem is I'm trying to play a specific sound onClick but also have a random array of other sound effects that play depending on what random number is generated. So in other words I want one designated soundpool that holds a specific sound, and another array of soundpools that have random effects that play depending on the random number if that makes sense.

Thanks for your help!

Here is my onClick that I want to perform the function. And I only have the one sound effect in my array as of now:

public void playC(View view) {

    if(number == 1){
        final int[] noSounds = {R.raw.nodriud};

     noSounds = new SoundPool(7, AudioManager.STREAM_MUSIC, 0);
     mCSoundId = notes.load(getApplicationContext(), R.raw.note1_c, 1);
     notes = new SoundPool(7, AudioManager.STREAM_MUSIC, 0);


        notes.play(mCSoundId, LEFT_VOLUME, RIGHT_VOLUME, PRIORITY, NO_LOOP, NORMAL_PLAY_RATE);
    }else {

        noSounds.play(noSounds[number], LEFT_VOLUME, RIGHT_VOLUME, PRIORITY, NO_LOOP, NORMAL_PLAY_RATE);
    }

}




Aucun commentaire:

Enregistrer un commentaire