How to play .mp3 file in a Android Emulator?

To play .mp3 file from sdcard of the emulator follow the steps.

  1. Copy .mp3 file from your hard drive location. e.g. d:\songs\song1.mp3
  2. Open any new eclipse project. File -> New -> Android Project.
  3. In Eclipse Click on the icon “Opens the Android SDK and AVD Manger” from the toolbar.
  4. Create New AVD, by choosing, select target greater than 1.6.
  5. Upon successful creation start the AVD.
  6. In Eclipse, Goto DDMS perspective. Window -> Open Perspective -> DDMS.
  7. In DDMS Perspective, select the device (AVD) which is currently running from the Devices Panel.
  8. On the right panel from “File Explorer”, Select SDCARD folder.
  9. On the tool bar select the button “Push a file on to the device”.
  10. Select the .mp3 file from the location.
  11. Goto Java Perspective. Window-> Open Perspective -> JAVA.
  12. Write the following Code.

String PATH_TO_FILE = “/sdcard/a.mp3”;
MediaPlayer mp1 = new MediaPlayer();
try

       {
mp1.setDataSource(PATH_TO_FILE);
mp1.prepare();
mp1.start();
}
       catch (IllegalArgumentException e)
      {
// TODO Auto-generated catch block
e.printStackTrace();
}
      catch (IllegalStateException e)
      {
// TODO Auto-generated catch block
e.printStackTrace();
}
      catch (IOException e)
      {
// TODO Auto-generated catch block
e.printStackTrace();
}
Run the project…..!!!!
Advertisements

4 thoughts on “How to play .mp3 file in a Android Emulator?

  1. You can’t. The emulator does not support Bluetooth, as mentioned in the SDK’s docs and on several other places.

    And you already discovered this yourself: “the adapter is returning null value, which means the android emulator is not having bluetooth capability”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s