2. Add a New Button
LinearLayout (vertical)
Starting Another Activity
Create the Second Activity
goNextActivity() Method
Build an Intent
Add a startActivity Method
Last Workshop
9. SoundPool
an Android library
specifically targeted for playing short audio clips
Supported Audio Formats
wav / ogg
Adding Audio
sound01.wav
MediaPlayer
for longer sound files or streams
10. Step 1 : Preparing an Audio file
Step 2 : Declaring Variables
Step 3 : Loading an Audio file
Step 4 : Playing an Audio file
Step 5 : Releasing SoundPool resources
Adding Audio
11. Add raw folder under res folder
Put your audio file into folder res/raw
Step 1 : Preparing an Audio file
Adding Audio
12. Edit MyActivity.java
Declare 2 Variables in MyActivity class
Step 2 : Declaring Variables
Adding Audio
…
}
*To use SoundPool, import SoundPool class
13. Edit MyActivity.java
Add onResume() method to MyActivity class
Step 3 : Loading an Audio file
Adding Audio
res/raw folder
file extension can be omitted
system calls this method when the activity comes to the foreground
14. Edit MyActivity.java
Add playAudio() method to MyActivity class
Edit res/layout/activity_my.xml
Add onClick attribute to ImageView element
Step 4 : Playing an Audio file
Adding Audio
15. Edit MyActivity.java
Add onPause() method to MyActivity class
Step 5 : Releasing SoundPool resources
Adding Audio
system calls this method when another activity is started