0

I'm trying to play a beep at a specified frequency for a specified length of time. How is this achieved in android? I noticed that their is an AudioTrack api but they don't provide any easy examples on its usage.

user1406186
  • 940
  • 3
  • 16
  • 28

1 Answers1

0

Soundpool Android Dev

Put the audio in the raw folder


SoundPool soundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
int soundId = soundPool.load(context, R.raw.beep, 1);
// soundId for reuse later on

soundPool.play(soundId, 1, 1, 0, 0, 1);
//(soundId , LEFT_VOLUME_VALUE , RIGHT_VOLUME_VALUE, SOUND_PLAY_PRIORITY , MUSIC_LOOP ,PLAY_RATE)

Use the PLAY_RATE attribute to change the frequency of the music being played

and use the MUSIC_LOOP to determine how many times it plays

Narendra_Nath
  • 4,578
  • 3
  • 13
  • 31