public void initSound(){ bgMusic[0]=MediaPlayer.create(this, R.raw.screen_bg); bgMusic[0].setLooping(true); bgMusic[0].setVolume(0.3f, 0.3f); soundPool=new SoundPool(4, AudioManager.STREAM_MUSIC, 100); soundMap=new HashMap(); soundMap.put( 0, soundPool.load(this, R.raw.awp_fire,1)); soundMap.put( 1, soundPool.load(this, R.raw.awp_fire,1)); } public void playSound(int sound,int loop){ if(!musicFlag){ return; } AudioManager manager=(AudioManager) this.getSystemService(Context.AUDIO_SERVICE); float streamVolumeCurrent=manager.getStreamVolume(AudioManager.STREAM_MUSIC); float streamVolumeMax=manager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); float volume=streamVolumeCurrent/streamVolumeMax; soundPool.play(soundMap.get( sound), volume, volume, 1, loop, 0.5f); }
act_Main.playSound(1, 0);