Audio Playback
Create a new class in the com.bignerdranch.android.hellomoon package named AudioPlayer. Leave its superclass as java.lang.Object.
In AudioPlayer.java, add a member variable to hold an instance of MediaPlayer and methods to stop and play this instance.
Listing 13.6 Simple playback code using MediaPlayer
(AudioPlayer.java
)
public class AudioPlayer { private MediaPlayer mPlayer; public void stop() { if (mPlayer != null) { mPlayer.release(); mPlayer = null; } } public void play(Context ...
Get Android Programming: The Big Nerd Ranch Guide 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.