soundpool

Playing Multiple sounds at the same time in Android

廉价感情. 提交于 2019-11-28 01:19:30
问题 I am unable to use the following to code to play multiple sounds/beeps simultaneously. In my onclicklistener I have added: public void onClick(View v) { mSoundManager.playSound(1); mSoundManager.playSound(2); } But this plays only one sound at a time, sound with index 1 followed by sound with index 2. How can I play at least 2 sounds simultaneously using this code whenever there is an onClick() event? public class SoundManager { private SoundPool mSoundPool; private HashMap<Integer, Integer>

How to properly use SoundPool on a game?

筅森魡賤 提交于 2019-11-27 23:22:42
I'm having performance issues while using SoundPool. Everytime I play a sound, the frame rate drops. I added some logs and I can see on logcat that the "play" function sometimes takes 8ms. I'm using *.ogg files and the SoundPool initialization is done on the app startup: mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); mSoundPool = new SoundPool(size, AudioManager.STREAM_MUSIC, 0); mSoundPoolMap = new HashMap<Integer, Integer>(); mSoundPoolMap.put(index, mSoundPool.load(context, R.raw.shot, 1)); To play the sound, I use the following code (inside the game loop):

Playing sound over speakers while playing music through headphones

旧时模样 提交于 2019-11-27 23:17:14
I have an AudioTrack streaming via headphones. I have to send a SoundPool to built-in speakers only, without interrupting the AudioTrack playing over the headphones. Any hacks gangsters? Michael Many Android devices use a single output thread in the AudioFlinger / audio HAL for all local playback (earpiece, speaker, wired headset/headphones), making different routing of two tracks simultaneously impossible (which is why on many devices the media streams are forcibly muted if a notification is played and you've got a wired headset attached; because otherwise you'd hear the music in the

set Audio Attributes in SoundPool.Builder class for API 21

家住魔仙堡 提交于 2019-11-27 22:11:26
问题 I am following an Android Programming video lecture series which was designed in the pre-API 21 times. Hence it tells me to create a SoundPool variable in the following manner. SoundPool sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0); //SoundPool(int maxStreams, int streamType, int srcQuality) However, I want to use this SoundPool for API 21 as well. So, I am doing this: if((android.os.Build.VERSION.SDK_INT) == 21){ sp21 = new SoundPool.Builder(); sp21.setMaxStreams(5); sp = sp21.build()

Android SoundPool: get notified when end of played

好久不见. 提交于 2019-11-27 21:18:52
This sound so simple that I can't figure out why I can't find the answer lol I have a working sound pool class (thanks to a tutorial and some tweaking I did), and it works fine. the problem now is that I want to be able to change my background music randomly. (not always have the same music in a loop but have 2 or 3 and when one finishes I play one of the 2 others). problem is I can't find a way to get notified that the music has finished playing. Any ideas ? Jason It can't be done with SoundPool as far as I can tell. The only audio 'player' that I know which can provide a completion

Soundpool plays only first 5 secs of file. Why?

无人久伴 提交于 2019-11-27 20:37:04
I use Soundpool in my app, so far it works good, but I do have a wav file which is 10 secs. Unfortunately, soundpool plays only the first 5 secs. How to make soundpool to play the whole track? I have converted wav to -- ogg and mp3 still the same issue. It plays only the first 5 secs. Any help would be much appreciated. //set up audio player mSoundPool = new SoundPool(20, AudioManager.STREAM_MUSIC, 0); //load fx mSoundPoolMap.put(RAW_1_1, mSoundPool.load(this, R.raw.loop1, 1)); //playing soundpool case R.id.button1: mSoundPool.stop(mStream1); mStream1= mSoundPool.play(mSoundPoolMap.get(RAW_1_1

What is the best way to get an audio file duration in Android?

送分小仙女□ 提交于 2019-11-27 16:17:34
问题 I'm using a SoundPool to play audio clips in my app. All is fine but I need to know when the clip playback has finished. At the moment I track it in my app by obtaining the duration of each clip using a MediaPlayer instance. That works fine but it looks wasteful to load each file twice, just to get the duration. I could roughly calculate the duration myself knowing the length of the file (available from the AssetFileDescriptor) but I'd still need to know the sample rate and the number of

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

孤者浪人 提交于 2019-11-27 15:21:47
I am searching a work-around for my problem specified in this question: How to disable the wired headset programmatically in Java As mentioned there, I am getting audio in both my speakers and headphones. Can someone please tell me how to mute the audio in the headset programmatically , while letting it play undiminished on speaker? 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

Playing multiple sounds using SoundManager

这一生的挚爱 提交于 2019-11-27 12:56:45
If I play a single sound, it runs fine. Adding a second sound causes it to crash. Anyone know what is causing the problem? private SoundManager mSoundManager; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); 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)findViewById(R.id.SoundButton); SoundButton.setOnClickListener(new OnClickListener

android soundpool heapsize overflow

社会主义新天地 提交于 2019-11-27 09:19:16
I get this error hundreds of times when I run in Debug, it doesn't seem to affect the program, but how do I get rid of it? I know it can be traced back to the SoundPool based on other posts 09-15 09:03:09.190: ERROR/AudioCache(34): Heap size overflow! req size: 1052672, max size: 1048576 SoundPool is hard code the buffer size as 1M for all loaded file. So you probably will get 'heap size overflow' error when you load too much files into SoundPool. I also have this issue on a game project that will load game sound FX into SoundPool and the solution is as follow: Play long/large background music