相关疑难解决方法(0)

在Android中同时播放多个声音

我无法使用以下代码同时播放多个声音/哔声.在我的onclicklistener我已经加入:

public void onClick(View v) { 
     mSoundManager.playSound(1); 
     mSoundManager.playSound(2); 
} 
Run Code Online (Sandbox Code Playgroud)

但是这一次只播放一个声音,声音索引为1,声音索引为2.

每当有onClick()事件时,如何使用此代码同时播放至少2个声音?

public class SoundManager {

private  SoundPool mSoundPool; 
private  HashMap<Integer, Integer> mSoundPoolMap; 
private  AudioManager  mAudioManager;
private  Context mContext;


public SoundManager()
{

}

public void initSounds(Context theContext) { 
     mContext = theContext;
     mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0); 
     mSoundPoolMap = new HashMap<Integer, Integer>(); 
     mAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);         
} 

public void addSound(int Index,int SoundID)
{
    mSoundPoolMap.put(1, mSoundPool.load(mContext, SoundID, 1));
}

public void playSound(int index) { 

     int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); 
     mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, …
Run Code Online (Sandbox Code Playgroud)

audio android soundpool

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

audio ×1

soundpool ×1