From the course: Android Development Tips
Unlock this course with a free trial
Join today to access over 22,400 courses taught by industry experts.
Play sounds with SoundPool - Android Tutorial
From the course: Android Development Tips
Play sounds with SoundPool
- [Instructor] In a previous tip, I described how to play a long running sound that's packaged as an app asset with media player. I showed how to copy the file from the assets directory to internal storage, and then play the file from there. With shorter sounds, where the file is less than one megabyte in size, you can play the file with SoundPool. The SoundPool class can load a file directly from assets, so you don't have to take the step of copying it to a new location. And you can cache the file in memory, as an activity starts up, so you won't have any latency the first time you play it. This makes SoundPool ideal for game sounds, and other effects that have to be played multiple times. In this starting project, in the assets directory, I've included two wave files. They're short files, and they're each less than one megabyte in size, so they're ideal for demonstrating the SoundPool class. In the main activity class, I'll declare a couple of private fields. The first will be an…
Contents
-
-
-
Communicate with Snackbar messages6m 15s
-
Manage view components with Butter Knife6m 41s
-
Create a reusable dialog class9m 22s
-
Convert a layout to ConstraintLayout7m 13s
-
Manage global data with singletons5m 37s
-
Convert image files to WEBP format6m 5s
-
Create an Espresso user interface test5m 18s
-
Create classes for Android with Kotlin5m 12s
-
Run background tasks in intent services8m 51s
-
Send broadcast messages with EventBus8m 44s
-
Handle events with Java 8 syntax5m 51s
-
Improve forms with design layouts7m 55s
-
Display draggable rows in a list of data8m 1s
-
Manage persistent data with Realm10m 23s
-
Play an audio file from assets8m 56s
-
Send an SMS message from an app7m 56s
-
Get a list of audio files on a device8m 32s
-
Play sounds with SoundPool8m 45s
-
Display the build date of an APK file6m 47s
-
Build Kotlin classes with properties7m 32s
-
Manage versioning with Gradle variables6m 8s
-
Use reporting tools from the Google Play Console4m 44s
-
Make web service calls with Retrofit10m 39s
-
Make asynchronous calls with Retrofit4m 6s
-
Send request parameters with Retrofit4m
-
Upgrade a project to Android Studio 3.04m 47s
-
Clean up calls to findViewById()2m 58s
-
Create adaptive launcher icons5m 47s
-
Use XML and downloadable fonts6m 40s
-
Explore a device's file system4m 55s
-
Profile an app's memory usage3m 52s
-
Manage an SQLite database with Room9m 17s
-
Manage background threads with Executors5m 32s
-
Track vital stats in a published app3m 4s
-
Inspect database files with DB Browser4m 41s
-
Execute tasks with JobScheduler7m 29s
-
Create Room entity classes in Kotlin8m 22s
-
Create Room DAO classes in Kotlin4m 13s
-
Upgrade to Android Studio 3.13m 22s
-
Convert a project to use Kotlin3m 20s
-
Handle events with Kotlin lambdas6m 13s
-
Manage menus with when3m 44s
-
Define global constants with Kotlin6m 12s
-
Use Kotlin data and enum classes5m 24s
-
Create inheritance hierarchies in Kotlin6m 8s
-
Manage data collections in Kotlin5m 45s
-
Sort data collections with Kotlin5m 33s
-
Filter data collections with Kotlin3m 52s
-
Create Kotlin extension functions2m 31s
-
Use support functions from Android KTX4m 30s
-
Use virtual devices with Google Play3m 50s
-