Introduction to [Android] soundpool

The main application scenario is game development. The sound is short and dense. Use this API to implement it

Pool: a linked list is implemented. The old resources will not be released, but will be saved and reused when used

Too many objects will not be created

Create a directory raw in the res resource directory, which means uncompressed resources. It will generate an ID in the R file

Get the soundpool object through new soundpool (maxstream, streamtype, srcquality). Parameters: maxstream is the maximum number of sounds, audiomanager.stream_ MUSIC , 0

Call the load() method of the soundpool object. Parameters: context, resource ID r.raw.xxx, 1, and get an int soundid

The above method needs to be placed in the oncreate () method because it loads resources asynchronously

Call the play() method of soundpool object to play. Parameters: soundid, left channel 1.0F, right channel 1.0F, priority 0, loop 0, playback rate 1.0F

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>