soundpool

MediaPlayer vs SoundPool for only 1 simultaneous stream

╄→гoц情女王★ 提交于 2019-12-06 15:04:32
I'm working on a game in which one single sound is played each time the phone is shaked. Does it make sense to use a SoundPool and load sounds in the onCreate of my activity, or is it ok to create a mediaplayer each time, as shown below: private void onShake() { MediaPlayer mp= MediaPlayer.create(this, whipSound[currentWhip][force]); mp.start(); } My guess is that SoundPool is better because the sounds are loaded only once. Am I right? Thanks Julien As expected, SoundPool is much faster... marcosbeirigo You can create the mediaPlayer outside the onShake method, and then reset and start it on

Android soundpool timing

对着背影说爱祢 提交于 2019-12-06 03:02:55
Is there a reliable way to prevent truncating of sounds in soundpool? I have had some success with the sleep() function between sounds, but they still sometimes miss the last bit of sound before starting another sound. My app plays short sounds in sequence. Jerry Although this is an old question, I thought I would post something here since I couldn't find a solution to this problem online but did come up with something of a solution... I get the duration of each sound (using MediaPlayer) when my app starts up, and store the R.id.sound_name value and the duration together. I can then play the

Android soundpool rate range?

女生的网名这么多〃 提交于 2019-12-06 00:29:25
Android's soundpool.play [documentation][1] says " The playback rate allows the application to vary the playback rate (pitch) of the sound. A value of 1.0 means play back at the original frequency. A value of 2.0 means play back twice as fast, and a value of 0.5 means playback at half speed. ". However, when I set the rate to 1.49f, I hear silence. 1.485f renders correctly (it's ogg file). Is this specific to my handset, is the documentation wrong, or am I being foolish in some other way? [1]: http://developer.android.com/reference/android/media/SoundPool.html#play(int , float, float, int, int

Android L SoundPool.load() regression

本小妞迷上赌 提交于 2019-12-04 08:03:50
问题 On Android L - the latest developer preview (Nexus 5), there seems to be a regression in the SoundPool.load() method which takes >5 seconds to load a sample (<100kb), where samples were loaded on pre-L systems instantly with the very same code. I tried OGG or MP3, both with same results. Tried different sizes but all under 100kb. Seems as 40kb or 80kb does not make any difference, so does OGG or MP3. Loading is always around 5s delay. This seems as yet another regression in SoundPool after

android:play audio files using single mediaplayer object and also display images

依然范特西╮ 提交于 2019-12-04 06:02:37
问题 i need to display images and play corresponding audio files one after the other. i tried to create multiple media player objects but it shows error(1, -17) so plz help guys i am running out of time. Right now i have a handler which plays audio file and then get the duration of that audio file while playing another audio file this is my approach but i am unable to play some 10 files below is my sample code img.setBackgroundResource(R.drawable.d002_p001); d002_ae_p001 = MediaPlayer.create(this,

How to Sync Sounds using SoundPool

时光怂恿深爱的人放手 提交于 2019-12-04 05:28:42
I have been trying to get a few sounds to play at the same time; currently i'm using a shared instance of SoundPool. I would like 1, 2 or 3 sounds to be played at the exact same time with no lag. When calling SoundPool.play(...) X number of times in succession, the sounds are played in that order as one might think. what is the proper what to achieve this where i can prepare all of the sounds to be played at the same time and then play them as one? Sudo Code: SoundPool _soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0); _soundPool.load(_context, soundId1, 1); _soundPool.load(_context

Why is my SoundPool mute?

空扰寡人 提交于 2019-12-03 08:46:12
I setup my SoundPool , and load a sound resource as this in onCreate() : soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0); soundId = soundPool.load(this, R.raw.edible_underwear, 1); And then I try to play this sound twice in a onClick() , one slow mostly in left speaker, and one fast mostly in the right speaker: soundPool.play(soundId, 0.9f, 0.1f, 0, -1, 0.7f); soundPool.play(soundId, 0.1f, 0.1f, 0, -1, 1.5f); No sound can be heard. I have fiddled with the volumes, priorities and rates. So far to no avail. Am I missing something obvious? Turns out that SoundPool have two bugs

Android L SoundPool.load() regression

匆匆过客 提交于 2019-12-02 19:25:11
On Android L - the latest developer preview (Nexus 5), there seems to be a regression in the SoundPool.load() method which takes >5 seconds to load a sample (<100kb), where samples were loaded on pre-L systems instantly with the very same code. I tried OGG or MP3, both with same results. Tried different sizes but all under 100kb. Seems as 40kb or 80kb does not make any difference, so does OGG or MP3. Loading is always around 5s delay. This seems as yet another regression in SoundPool after looping has been broken in 4.3. The issue is easily reproducible with: pool = new SoundPool(6,

Loading MP3s into the Sound Pool in Android

我只是一个虾纸丫 提交于 2019-12-02 12:14:25
问题 I want to load a couple of MP3s into the sound pool, but I will only be using these MP3s on Activity 3, is it possible to load the MP3s in Activity 1? Or is this limited to the Activity that loads it uses it? I can't find the answer in the docs. 回答1: You can load them anytime and use them everywhere. The best thing to re-use the SoundPool object would be to extend the Application class and declare a private variable in there that is your SoundPool . Something like: class MyApp extends

android:play audio files using single mediaplayer object and also display images

淺唱寂寞╮ 提交于 2019-12-02 07:36:13
i need to display images and play corresponding audio files one after the other. i tried to create multiple media player objects but it shows error(1, -17) so plz help guys i am running out of time. Right now i have a handler which plays audio file and then get the duration of that audio file while playing another audio file this is my approach but i am unable to play some 10 files below is my sample code img.setBackgroundResource(R.drawable.d002_p001); d002_ae_p001 = MediaPlayer.create(this, R.raw.d002_ae_p001); handler.postDelayed(new Runnable() { @Override public void run() { // TODO Auto