-4

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.

  • 1
    First, 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 Answers1

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