日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

java 手机声音提醒功能_java – 同时播放声音Android

發布時間:2023/12/19 Android 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 手机声音提醒功能_java – 同时播放声音Android 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我在

Android上創造了一個游戲,而且我已經把這個問題放在一段時間了,現在我剛剛回來了.在我的游戲中,我有一個背景拍攝,槍聲,爆炸等等,我需要能夠同時玩.現在,當我在SoundPool類上打電話時,當前播放的聲音被中斷,新的播放聲音開始播放.我的SoundManager類在下面以及用法.任何幫助將不勝感激,因為這真的是我的第一個游戲,我需要這么多的音效.謝謝!

public class SoundManager {

private SoundPool mSoundPool;

private HashMap mSoundPoolMap;

private AudioManager mAudioManager;

private Context mContext;

public SoundManager(Context theContext) {

mContext = theContext;

mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);

mSoundPoolMap = new HashMap();

mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);

}

public void addSound(int index, int SoundID) {

mSoundPoolMap.put(index, mSoundPool.load(mContext, SoundID, 1));

}

public void playSound(int index) {

float streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_RING);

streamVolume = streamVolume / mAudioManager.getStreamMaxVolume(AudioManager.STREAM_RING);

mSoundPool.play((Integer) mSoundPoolMap.get(index), streamVolume, streamVolume, 1, 0, 1f);

}

public void playLoopedSound(int index) {

float streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);

streamVolume = streamVolume / mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);

mSoundPool.play((Integer) mSoundPoolMap.get(index), streamVolume, streamVolume, 1, -1, 1f);

}

}

…這里是我如何使用類的一個例子.

SoundManager sm = new SoundManager(this);

sm.addSound(0, R.raw.explosion);

sm.playSound(0);

…所以用這種風格,我把所有的聲音添加到SoundPool上,然后根據用戶輸入,我只想播放聲音.這看起來正確嗎?或者我應該嘗試不同的方法嗎?

總結

以上是生活随笔為你收集整理的java 手机声音提醒功能_java – 同时播放声音Android的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。