I have no idea about choosing a audio file .mp3 , wma... in sd card (That's in the Setting Activity and send the sound to the Main activity for playing it by user). And what kind of information (of this sound ) can i send to Main activity to play it? .I'm sorry, but my 'reputation' is too low to post a picture. Thanks.
Asked
Active
Viewed 35 times
-4
-
1First, please frame question properly. Atleast, use proper English and remove these extra (...) and (???). Now to your question, if I am not getting it wrong you need a default sound for your app you can store any sound/video or any other file in res/raw directory and then reference it. – Amit Tripathi Jan 24 '15 at 14:14
-
Sorry ,i just want to choose file in sd card ( in the Setting Activity) and send the sound to the Main activity for playing it by user. – Kỳ Đoàn Văn Jan 24 '15 at 14:28
1 Answers
0
Okay, Here you go
Set the path of file like this-
String SD_CARD_PATH = Environment.getExternalStorageDirectory().toString();
new File(SD_CARD_PATH + "/" + "your_file_name.mp3");
Code from this SO answer
and use android MediaPlayer to play the song.
public void playSong(String file_path){
MediaPlayer mediaPlayer = new MediaPlayer();
try{
mediaPlayer.setDataSource(file_path);
mediaPlayer.prepare();
mediaPlayer.start();
} catch (Exception e) {
e.printStackTrace();
}
}

Community
- 1
- 1

Amit Tripathi
- 7,003
- 6
- 32
- 58
-
Thanks. But I don't know exactly my file :( "your_file_name.mp3"), because the user will choose it from their phone. I'm looking for a brouser, might be. – Kỳ Đoàn Văn Jan 24 '15 at 14:55
-
See this http://stackoverflow.com/questions/7856959/android-file-chooser – Amit Tripathi Jan 24 '15 at 14:59
-
Thanks a lots @Amit . I've built one. But, when i get the file (path). how can i play it ? – Kỳ Đoàn Văn Jan 26 '15 at 06:54
-
-