【項目執行個體】android開發遊戲音效代碼執行個體

來源:互聯網
上載者:User

標籤:android   des   style   blog   color   cti   

//音效的音量   int streamVolume;   //定義SoundPool 對象 private SoundPool soundPool;   //定義HASH表 private HashMap<Integer, Integer> soundPoolMap;   /*************************************************************** * Function: initSounds();   * Parameters: null   * Returns: None.   * Description: 初始化聲音系統   * Notes: none.   ***************************************************************/   public void initSounds() { //初始化soundPool 對象,第一個參數是允許有多少個聲音流同時播放,第2個參數是聲音類型,第三個參數是聲音的品質 soundPool = new SoundPool(100, AudioManager.STREAM_MUSIC, 100);   //初始化HASH表 soundPoolMap = new HashMap<Integer, Integer>();   //獲得聲音裝置和裝置音量 AudioManager mgr = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);   streamVolume = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);   }   /*************************************************************** * Function: loadSfx();   * Parameters: null   * Returns: None.   * Description: 載入音效資源   * Notes: none.   ***************************************************************/   public void loadSfx(int raw, int ID) { //把資源中的音效載入到指定的ID(播放的時候就對應到這個ID播放就行了) soundPoolMap.put(ID, soundPool.load(context, raw, ID));   }   /*************************************************************** * Function: play();   * Parameters: sound:要播放的音效的ID, loop:迴圈次數   * Returns: None.   * Description: 播放聲音   * Notes: none.   ***************************************************************/   public void play(int sound, int uLoop) {     soundPool.play(soundPoolMap.get(sound), streamVolume, streamVolume, 1, uLoop, 1f); }         

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.