0

how can i get a Audio file and Run it from any path in Android ??

any one help me please

I'm beginner
thanks in Advance

  • 1
    What do you mean by "any path"? Have you ever programmed anything before? – Max Leske Nov 30 '14 at 18:39
  • Fro where you want to get the file? And, yes supporting @MaxLeske comment too. B/w I will suggest - http://developer.android.com/guide/topics/media/mediaplayer.html as OP is a beginner in Android. – Kanak Sony Nov 30 '14 at 18:44

2 Answers2

1

It depends what you are looking for. Check this post: AudioTrack, SoundPool or MediaPlayer Which Should I use?

Then, if you want to use a SoundPool:

Step 1: create a SoundPool

SoundPool mSoundPool = new SoundPool(numMaxStreams, AudioManager.STREAM_MUSIC, 100);

Step 2: create a folder on your asset with your sounds (for example folder called music)

Step 3: load a sound:

Integer mySound = mSoundPool.load(getActivity(), R.music.mySound, 1);

Step 4: play a sound

AudioManager mgr = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
int volume = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);

mSoundPool .play(mySound, volume, volume, 1, 0, 1.0f);
Community
  • 1
  • 1
DavidGSola
  • 697
  • 5
  • 17
0
//set up MediaPlayer     
MediaPlayer mp = new MediaPlayer();     
try { 
      mp.setDataSource("/path/to/file");
      mp.prepare();
      mp.start();
} catch (Exception e) {
      e.printStackTrace();
}   

Like so!

An SO User
  • 24,612
  • 35
  • 133
  • 221