1 @ Override
2 public void onCreate (Bundle savedInstanceState ){
3 super. onCreate (savedInstanceState );
4 setContentView (R. layout. main );
5
6 // create an object
7 // The first parameter specifies that the maximum number of audio streams in the audio pool is 10.
8 // The third parameter, with a sound quality of 5
9 spool = new SoundPool (1, AudioManager. STREAM_SYSTEM, 10 );
10
11 // capture audio streams from resources or files
12 hit = spool. load (this, R. raw. sound, 0 );
13
14 Button btn = (Button) findViewById (R. id. Button01 );
15 btn. setOnClickListener (new OnClickListener (){
16
17 @ Override
18 public void onClick (View v ){
19 // TODO Auto-generated method stub
20
21 // play the audio. You can set the Left and Right volume separately. You can set the priority, loop times, and rate.
22 // the highest speed is 2, the lowest is 0.5, and the normal is 1
23 spool. play (hit, 2, 1, 0, 0, (float) 1.4 );
24
25 // spool. play (soundID, leftVolume, rightVolume, priority, loop, rate)
26}
27 });