Accessing Assets

BeatBox will end up doing a lot of work related to asset management: finding assets, keeping track of them, and eventually playing them as sounds. To manage all this, create a new class called BeatBox in com.bignerdranch.android.beatbox. Go ahead and add a couple of constants: one for logging and one to remember which folder you saved your boxing grunts in.

Listing 19.10  New BeatBox class (BeatBox.kt)

private const val TAG = "BeatBox"
private const val SOUNDS_FOLDER = "sample_sounds"

class BeatBox {

}

Assets are accessed using the AssetManager class. You can get an AssetManager from any Context. Since BeatBox will need one, give it a constructor that takes in an AssetManager and stashes it for later.

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.