Class' SoundPool' is for playing sound in Android.
Use SoundPool.Builder instead of SoundPool in API 21.
But, I use SoundPool in this post.
Example
- SoundPool pool=new SoundPool(1, AudioManager.STREAM_MUSIC,0);
- int hahaha=pool.load(this,R.raw.hahaha,1);
- pool.play(hahaha,1,1,0, 0,1);
Line 1 : Initialize
First parameter : Default 1
Second parameter : Default STREAM_MUSIC
last parameter : default 0
Line 3 : Load sound file.
First parameter : Context
Second parameter : sound file name(path : res/raw/ )
Third parameter : priority, default 1
P.S return value is integer
Line 5 : play the sound
First parameter : Sound id, integer
Second,Third parameter : Volume
Forth parameter : priority default 0
Fifth parameter : Repeat, no repeat is 0
Last parameter : Speed of play, normal is 1
P.S Your mp3 file copy to raw folder(res/raw/ )
No comments:
Post a Comment