android - Playing multiple sounds using SoundManager -


If I play a sound, then it's running fine.

By adding another sound, it crashes

Anyone know what the problem is?

  Private Sound Manager mSoundManager; /** Called when the activity is first created. * / @ Override Crate on Public Zero (Bundle Saved Instantstate) {Super. Contents (Saved Instantstate); SetContentView (R.layout.sos); MSoundManager = New SoundManager (); MSoundManager.initSounds (getBaseContext ()); MsoundManager.addSound (1, R.raw.dit); MsoundManager.addSound (1, R.raw.dah); Button SOUNDBUTTON = (button) Find VBID (RID Sodabutan); SoundButton.setOnClickListener (New OnClickListener) {Public Zero onClick (see v) {mSoundManager.playSound (1); mSoundManager.playSound (2);}}); }  "itemprop =" text "> 
  msoundManager.addSound (1, R.raw.dit);  

You need to change the second line to:

  m.soundManager.addSound (2, R.raw.dah);  

To run multiple voices together, you must first tell the soundboard that in the announcement of SoundPool notice that I specify 20 streams. I have many guns and bad guys make noise in my game, and each has a very low sound loop,

Next we have the queue, place () with the sound every time it happens when a soundId is dropped into a stack, which I pop in whenever I have a timeout. This gives me permission to kill a stream, and it is used again again, I select 20 streams because my game is very noisy then sounds are washed out, so each app needs a magic number Will be.

I found this source, and runner & amp; Kill yourself queue

  private sound mSoundPool; Private Hashmap & lt; Integer, integer & gt; M.soundPoolMap; Private Audio Manager Maaudio Manager; Private reference mContext; Private vector & lt; Integer & gt; MAvailibleSounds = new vector & lt; Integer & gt; (); Private vector & lt; Integer & gt; MKillSoundQueue = new vector & lt; Integer & gt; (); Private handler mHandler = new handler (); Public Sound Manager () {} Public Zero Init Voice (Reference to Reference) {mContext = theContext; M.soundPool = New SoundPool (20, Audio Manager. STREAM_MUSIC, 0); M.soundPoolMap = New Hashmap & lt; Integer, integer & gt; (); MAudioManager = (Audio Manager) mContext.getSystemService (reference. AUDIO_SERVICE); } Public Zero addSound {int Index, int soundID} {mAvailibleSounds.add (index); M.soundPoolMap.put (index, m.soundPool.load (mContext, SoundID, 1)); } Public Zero GameSound (Int Indexes) {// This is not a voice for obj, return. If (mAvailibleSounds.contains (index)) {int streamVolume = mAudioManager.getStreamVolume (AudioManager.STREAM_MUSIC); Int soundId = mSoundPool.play (m.soundPoolMap.get (index), streamwolume, streamwolm, 1, 0, 1f); MKillSoundQueue.add (soundId); // To stop the current sound schedule after set milliseconds mHandler.postDelayed (New Runnable) {Public Zero Run} {if (mKillSoundQueue.isEmpty ()) {mSoundPool.stop (mKillSoundQueue.firstElement ());}} }}, 3000); }}  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -