The sound code of Android development

Source: Internet
Author: User
Tags hash

//sound effects volume

int streamvolume;

Define Soundpool object Private Soundpool Soundpool;

Define hash table private HASHMAP soundpoolmap;

/*************************************************************** * Function:initsounds ();

* Parameters:null

* Returns:none.

* Description: Initialize sound system

* Notes:none.

***************************************************************/

The public void Initsounds () {///initializes the Soundpool object, the first parameter is how many sound streams are allowed to play at the same time, the 2nd argument is the sound type, and the third parameter is the quality of the sound Soundpool = new Soundpool (100, Audiomanager.stream_music, 100);

Initialize hash Table Soundpoolmap = new HashMap ();

Obtain sound equipment and device volume Audiomanager mgr = (audiomanager) context.getsystemservice (Context.audio_service);

Streamvolume = Mgr.getstreamvolume (Audiomanager.stream_music);

}

/*************************************************************** * FUNCTION:LOADSFX ();

* Parameters:null

* Returns:none.

* Description: Loading sound resources

* Notes:none.

***************************************************************/

public void Loadsfx (int raw, int ID) {//load the sound effects in the resource to the specified ID (play the same as the ID when playing) soundpoolmap.put (ID, soundpool.load ( Context, raw, ID));

}

/*************************************************************** * Function:play ();

* Parameters:sound: ID of the sound effect to play, loop: number of cycles

* Returns:none.

* Description: Play sound

* Notes:none.

***************************************************************/

public void Play (int sound, int uloop) {Soundpool.play (Soundpoolmap.get (sound), Streamvolume, Streamvolume, 1, Uloop, 1f) ; }

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.