2017-06-25 22 views
0

我想制作一个音乐播放器,可以播放存储卡上的所有音乐。 我使用此代码播放音乐,但我无法播放存储卡中的音乐,只能在原始文件夹中播放。如何在Android上设置自定义音乐?

MediaPlayer mp = MediaPlayer.create(this, R.id.raw.audio.mp3) 

我该做什么,所以我可以从SD卡播放音乐?

+0

https://stackoverflow.com/questions/19208078/playing-music-from-sd-card-works-on-emulator-的可能的复制但并非在电话。 –

回答

0

使用接受URI的create版本,并为要播放的本地文件提供一个URI。

+0

是这样的? file:///sdcard/music.mp3 – user8211717

1

你会想要做这样的事情

Uri song = Uri.parse(location-of-song); //location-of-song is where the music is on the sd card 
    mPlayer = new MediaPlayer(); 
    mPlayer.setDataSource(getApplicationContext(), song); 
    mPlayer.start(); 
+0

我想从用户输入 – user8211717

+0

得到的位置,你会想要做这样的事情https://stackoverflow.com/questions/26983905/android-programming-making-a-uri -to-GET-音频的定位 – Pam

相关问题