This document provides instructions for uploading audio files to the SD card of an Android emulator so they can be played by a media player application being tested. It describes creating an SD card partition for the emulator, using DDMS to push files to the emulator's mnt/sdcard folder, and playing songs from the SD card by specifying their file paths. The document also gives examples of using the MediaPlayer class to play songs from raw resources or the SD card.
1. 10.2. Audio with SD Card
Oum Saokosal
Master of Engineering in Information Systems, South Korea
855-12-252-752
oum_saokosal@yahoo.com
2. Upload to SD Card of the Emulator
• Normally when you run the app on an Android
device, you will need to play a song from the
sdcard of the device.
• To place the song to the sdcard, simply copy it
and paste.
• However, to test it on the Emulator, you need
to push the file to the the Emulator.
See how-to in the next slide.
3. I. Create size for sdcard:
1. Go to AVD Manager
(Window -> AVD
Manager)
2. Click on your avd
(e.g.avd.2.3.3) -> Edit
3. Enter a size: 1000 for the
SD Card
4. Click Enter AVD to finish.
4. II. Upload a file to SD Card:
1. Go to DDMS -> File Explorer
2. In case you can't see the file, please run the Emulator first.
3. Browse to mnt/sdcard
4. Click on the button call "Push a file onto the device" to upload.
5. Play a Song from SD Card
• To play an embedded song:
MediaPlayer mp;
mp = MediaPlayer.create(this, R.raw.song1));
• To play a song from SD Card:
MediaPlayer mp;
mp = MediaPlayer.create(this,
Uri.parse("/sdcard/More Than I Can Say.mp3"));
6. • To Play with setDataSource() method:
MediaPlayer mp;
mp = new MediaPlayer();
try{
mp.reset();
mp.setDataSource("/sdcard/I love you.mp3");
mp.prepare();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
mp.start();