Creating a Custom Audio Playing Application

Appportunity

Build your own Android App Dev Empire

Get Instant Access

Of course, we aren't limited to using Android's built-in application for audio playback. We can write our own application that offers playback capabilities and more.

To enable this, Android includes a MediaPlayer class. This class is used for the playback and control of both audio and video. Right now we'll just be using the audio playback capabilities.

The simplest MediaPlayer example is to play back an audio file that is packaged with the application itself. In order to do that, an audio file should be placed within the application's raw resources. To do this using the Android Developer Tools on Eclipse, we need to create a new folder in our Project's res folder called raw as illustrated in

Figure 5-2. The Android Developer Tools will generate a resource id for this file in the R.java file (in the gen folder) with the syntax R.raw.file_name_without_extension.

▼ fc? Book Custom Audio Player Ti3src

▼ com.mobvcasting.customaudio ► |T| CustomAudioPlayer.java

▼ £0 com.mobvcasting.customaudio ▼ [¿J Rjava r&R

► © drawable » ^ layout T^i raw goodmorningandroid

assets

H goodmorningandroid.mp3

Q AndroidManifest.xmt i J default.properties

Figure 5-2. Custom audio player Eclipse Project layout showing audio file located in raw folder inside res folder.

Was this article helpful?

0 0

Post a comment