• 加载声音的过程


    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<Integer, Integer>();
    		soundMap.put(<span style="color:#ff0000;">0</span>, soundPool.load(this, R.raw.awp_fire,1));
    		soundMap.put(<span style="color:#ff0000;">1</span>, soundPool.load(this, R.raw.awp_fire,1));
    	}
    	
    	public void playSound(int <span style="color:#ff0000;">sound</span>,int<span style="color:#3333ff;"> loop</span>){
    		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(<span style="color:#ff0000;">sound</span>), volume, volume, 1, <span style="color:#3333ff;">loop</span>, 0.5f);
    	}


    0和1表示可选择的声音资源!

    act_Main.playSound(<span style="color:#ff0000;">1</span>, 0);


  • 相关阅读:
    JavaScript测试工具chai
    gradle初始仓库依赖(含junit)
    汇编和中断
    oracle-12c-ee安装
    pickle
    Python (zip, lambda, map, shallow copy, deepcopy)
    豆瓣源下载tensorflow
    Linux上XRDP可作为WIN的远程连接
    VNC连接远程Linux——废弃电脑作为运算机器
    MACOS 运行Keras报错
  • 原文地址:https://www.cnblogs.com/Anzhongliu/p/6092037.html
Copyright © 2020-2023  润新知