문제

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?

도움이 되었습니까?

해결책 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" />

다른 팁

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"); 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top