SoundPool soundPool;
public void initsound(){
soundPool=new SoundPool(4,AudioManager.STREAM_MUSIC,1);
soundPool.load(this,R.raw.th,1);
}
public void play(int loop){
AudioManager mgr=(AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
float streamVolume=mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
float streamVolumeMax=mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float volume=streamVolume/streamVolumeMax;
soundPool.play(R.raw.th, volume, volume, 1, loop, 1f);
}这两个方法有问题吗??
int soundID; public void initsound(){
soundPool=new SoundPool(4,AudioManager.STREAM_MUSIC,1);
soundID=soundPool.load(this,R.raw.th,1);
}
public void play(int loop){
AudioManager mgr=(AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
float streamVolume=mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
float streamVolumeMax=mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float volume=streamVolume/streamVolumeMax;
soundPool.play(soundID, volume, volume, 1, loop, 1f);
}
http://blog.csdn.net/ch_984326013/article/details/6615707