70 likes | 197 Views
10.2. Audio with SD Card. Prof. Oum Saokosal Master of Engineering in Information Systems, South Korea 855-12-252-752 oum_saokosal@yahoo.com. Upload to SD Card of the Emulator.
E N D
10.2. Audio with SD Card Prof. Oum Saokosal Master of Engineering in Information Systems, South Korea 855-12-252-752 oum_saokosal@yahoo.com
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.
I. Create size for sdcard: • Go to AVD Manager (Window -> AVD Manager) • Click on your avd (e.g.avd.2.3.3) -> Edit • Enter a size: 1000 for the SD Card • Click Enter AVD to finish.
II. Upload a file to SD Card: Go to DDMS -> File Explorer In case you can't see the file, please run the Emulator first. Browse to mnt/sdcard Click on the button call "Push a file onto the device" to upload.
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"));
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();