Question

enter image description here

I have an MP3 in my sdcard and I need to use its path for my setdatasource command. I have tried mp.setDataSource("/mnt/media_rw/sdcard/mymusic/thebomb.mp3"); along with many variations but it still won't work. And I don't think it has to do with the rest of the code.

How would I accomplish this?

Was it helpful?

Solution 2

Use this way:

 Uri uri = Uri.parse(Environment.getExternalStorageDirectory()+"/mymusic/thebomb.mp3");
 musicPlayer.setDataSource(uri); 

Add permission to your manifest.xml file.

  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

OTHER TIPS

I guess you are using Emulator.So the path of the SDCard can be get through Environment.getExternalStorageDirectory().Moreover your sdcard must contain that file.So you have to push your file in the SD card.

try this like...Simple mediaplayer play mp3 from file path?. Hope so it will help you.

 mpintro = MediaPlayer.create(this, Uri.parse(Environment.getExternalStorageDirectory().getPath()+ "/Music/intro.mp3"));
 mpintro.setLooping(true);
 mpintro.start();

Use the below code:

 musicPlayer.setDataSource("/sdcard/mymusic/thebomb.mp3"); 

Try with this -

mp.setDataSource(Environment.getExternalStorageDirectory()+"/mymusic/thebomb.mp3");

Try the following code and is working:

mp.setDataSource("/sdcard/mymusic/thebomb.mp3"); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top