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
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
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);
//set up MediaPlayer
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource("/path/to/file");
mp.prepare();
mp.start();
} catch (Exception e) {
e.printStackTrace();
}
Like so!