80,471
社区成员




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);
}
这两个方法有问题吗??
SoundPool soundPool;
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);
}