Wiring Up Assets for Use

Now that you have your asset filenames, you should present them to the user. Eventually, you will want the files to be played, so it makes sense to have an object responsible for keeping track of the filename, the name the user should see, and any other information related to that sound.

Create a Sound class to hold all of this. (Remember to let Android Studio generate your getters.)

Listing 18.12  Create Sound object (Sound.java)

p​u​b​l​i​c​ ​c​l​a​s​s​ ​S​o​u​n​d​ ​{​
 ​ ​ ​ ​p​r​i​v​a​t​e​ ​S​t​r​i​n​g​ ​m​A​s​s​e​t​P​a​t​h​;​
 ​ ​ ​ ​p​r​i​v​a​t​e​ ​S​t​r​i​n​g​ ​m​N​a​m​e​;​

 ​ ​ ​ ​p​u​b​l​i​c​ ​S​o​u​n​d​(​S​t​r​i​n​g​ ​a​s​s​e​t​P​a​t​h​)​ ​{​
 ​ ​ ​ ​ ​ ​ ​ ​m​A​s​s​e​t​P​a​t​h​ ​=​ ​a​s​s​e​t​P​a​t​h​; ...

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.