The Android SDK includes packages for working with all sorts of rich media. There are a couple of ways to work with audio: a class named SoundPool can be used to play very short sounds that have to be repeated, but for longer sounds such as music files you can use the MediaPlayer class from android.media. In this demonstration I’ll show you how to play a simple MP3 file that’s included in an app’s assets folder.
- [Voiceover] The Android STK includes packages…for working with all sorts of rich media.…There are a couple of different ways to work with audio.…A class named SoundPool…can be used to play very short sounds…that have to be repeated.…But for longer sounds such as music files…you can use the media player class.…Both of these classes…are members of the package "Andriod.media".…In this demonstration…I'll show you how to play a simple MP3 file…that's included in an apps assets folder.…
In this project named "audio player"…I've included this MP3 file.…In the apps current state…it has three buttoms at the bottom…of the main activity.…The "run code" button is just displaying a message…but the 'stop' button doesn't do anything…and the 'clear' button just clears the output.…My goal…is to open that MP3 file from the assets folder…and play it over the devices speakers.…I'm going to need a bit of code to do this…so I provided two gist files…that you can download and copy into your application.…
For each one, I'll start by creating a class…
Watch these Java tutorials to learn smarter, more efficient methods for Android app development.
- Preparing the development environment
- Packaging and running Android apps
- Optimizing Java code for Android
- Implementing event handler interfaces
- Defining custom callback methods
- Working with the Android SDK's Java packages
- Storing data
- Reading text files
- Parsing JSON and XML data
- Managing device sensors
- Playing audio