Playing Multiple sounds at the same time in Android

Having the following class to play sound fx using sound pool: public class SoundManager { public static int SOUNDPOOLSND_MENU_BTN = 0; public static int SOUNDPOOLSND_WIN = 1; public static int SOUNDPOOLSND_LOOSE = 2; public static int SOUNDPOOLSND_DRAW = 3; public static int SOUNDPOOLSND_TICK1 = 4; public static int SOUNDPOOLSND_TICK2 = 5; public static int SOUNDPOOLSND_OUT_OF_TIME … Read more

Android SoundPool.play() sometimes lags

thanks to Tim, using a Thread for playing seemed to workaround the problem successfully. Thread package org.racenet.racesow.threads; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import org.racenet.racesow.models.SoundItem; import android.media.SoundPool; /** * Thread for playing sounds * * @author soh#zolex * */ public class SoundThread extends Thread { private SoundPool soundPool; public BlockingQueue<SoundItem> sounds = new LinkedBlockingQueue<SoundItem>(); public boolean stop … Read more

Playing multiple sounds using SoundManager

mSoundManager.addSound(1,R.raw.dit); mSoundManager.addSound(1,R.raw.dah); You need to change the second line to: mSoundManager.addSound(2,R.raw.dah); In order to play multiple sounds at once, first you need to let the SoundPool know that. In the declaration of SoundPool notice that I specified 20 streams. I have many guns and bad guys making noise in my game, and each has a … Read more

How to mute audio in headset but let it play on speaker programmatically?

AudioManager am = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE); am.setMode(AudioManager.MODE_IN_CALL); am.setSpeakerphoneOn(true); And then play the sound through the AudioManager.STREAM_SYSTEM stream. When the sound’s finished playing be sure to return the audio manager to its previous state or it’ll stay on loudspeaker!!

Android : How to change Playback Rate of music using OpenSL ES

I have solved my problem. Here is my complete native code for OpenSL ES in case of anybody need this : #include <jni.h> #include<android/log.h> // LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog 넣어주세요 #define LOGV(…) __android_log_print(ANDROID_LOG_VERBOSE, “OSLESMediaPlayer”, __VA_ARGS__) #define LOGD(…) __android_log_print(ANDROID_LOG_DEBUG , “OSLESMediaPlayer”, __VA_ARGS__) #define LOGI(…) __android_log_print(ANDROID_LOG_INFO , “OSLESMediaPlayer”, __VA_ARGS__) #define LOGW(…) __android_log_print(ANDROID_LOG_WARN , “OSLESMediaPlayer”, __VA_ARGS__) #define LOGE(…) … Read more

Play sound using soundpool example

Create a folder named as raw under your_app/res/. Then paste your ringtone in this folder, for example your_app/res/raw/ringtone.mp3. Now use the following code: SoundPool soundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0); int soundId = soundPool.load(context, R.raw.ringtone, 1); // soundId for reuse later on soundPool.play(soundId, 1, 1, 0, 0, 1); Be sure to release the SoundPool resources … Read more