Playing music in android soundpool

Source: Internet
Author: User
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 });
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.