Playing Sounds

One last step: playing the sounds back. Add the play(Sound) method to BeatBox.

Listing 19.5  Playing sounds back (BeatBox.java)

 ​ ​ ​ ​m​S​o​u​n​d​P​o​o​l​ ​=​ ​n​e​w​ ​S​o​u​n​d​P​o​o​l​(​M​A​X​_​S​O​U​N​D​S​,​ ​A​u​d​i​o​M​a​n​a​g​e​r​.​S​T​R​E​A​M​_​M​U​S​I​C​,​ ​0​)​;​
 ​ ​ ​ ​l​o​a​d​S​o​u​n​d​s​(​)​;​
}​

p​u​b​l​i​c​ ​v​o​i​d​ ​p​l​a​y​(​S​o​u​n​d​ ​s​o​u​n​d​)​ ​{​
 ​ ​ ​ ​I​n​t​e​g​e​r​ ​s​o​u​n​d​I​d​ ​=​ ​s​o​u​n​d​.​g​e​t​S​o​u​n​d​I​d​(​)​;​
 ​ ​ ​ ​i​f​ ​(​s​o​u​n​d​I​d​ ​=​=​ ​n​u​l​l​)​ ​{​
 ​ ​ ​ ​ ​ ​ ​ ​r​e​t​u​r​n​;​
 ​ ​ ​ ​}​
 ​ ​ ​ ​m​S​o​u​n​d​P​o​o​l​.​p​l​a​y​(​s​o​u​n​d​I​d​,​ ​1​.​0​f​,​ ​1​.​0​f​,​ ​1​,​ ​0​,​ ​1​.​0​f​)​;}​ p​u​b​l​i​c​ ​L​i​s​t​<​S​o​u​n​d​>​ ​g​e​t​S​o​u​n​d​s​(​)​ ​{​ ...

Get Android Programming: The Big Nerd Ranch Guide, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.