SoundPool need play sound with tempo sync - android

i am developing a game similar to Simon (copycat) but in my case, i want to play de demo game making rhythms, but i can not get my sounds to be played at tempo time, i mean:
If i schedule the playback for 4 sounds each 300ms, it does asynchronously...
I am using SoundPool and i have tried to play the sounds from raw and from assets, and differente formats like mp3 and ogg.
I've tried using Chronometer as timer and also i've tried a second Thread using System.currentTimeMillis() to check the time to play each sample....both cases i've got the same result...async...
After some playbacks sometimes i get the demo to be played at time...40 percent of success
What i am doing wrong??
Thanks in advance

Related

How to speed up MediaPlayer buffering on Android

Hi I'm developing an application that uses Android MediaPlayer to play a background video usually of 30 seconds length.
With some videos that are less than 5-7MB the Player starts immediately, but when the video size goes over 10-15MB the video takes over 30 seconds before playing.
My question is: is there a way to speed up Android native MediaPlayer Buffering in order to play the first frame of the video as soon as it is available like YouTube?
Thanks in advance
Don't know much about android native MediaPlayer but got similar problems using ExoPlayer and solve it by using LoadControl. If you don't find any solution with MediaPlayer maybe think about use ExoPlayer. Here is the link for discussion about DefaultLoadControl:
https://github.com/google/ExoPlayer/issues/2438

Looping a Sound in Android

I'd like to create an application that plays a sound repeatedly at a regular interval. I've tried using the in onTick method for the CountdownTimer class and then using a MediaPlayer object to play the sound. This works for moderately slow rates of repeation (1 sound per second) but anything faster than that and the program doesn't work properly. I suspected that the issue was the length of the media file I used, but shortening it didn't seem to do anything. Any suggestions?

How to play multiple sounds simultaneously in Android?

I've been trying to make multiple sounds work simultaneously but I kept getting errors like Sample not ready and Error creating AudioTrack. Though I've taken care of the first error, the other error persists.
I'm using two mp3 files, that are away above 5 mb(>4 minutes) and thus was wondering if SoundPool is the right way to go about it? I can use Media Manager but it doesn't let me play multiple files simultaneously.
SoundPool is recommended for <1MB sound clips, so I'd use MediaPlayer in your case. You can call the following for each sound and they will play simultaneously:
MediaPlayer.create(YourActivity.this, R.raw.your_sound).start();
Or you can create multiple MediaPlayer objects and play a sound on each, then release() them.

SoundPool error: no more track names available

I'm having troubles with the soundpool class. Here it goes:
In my game app (music app btw) I need to reproduce at least 32 short sounds at the same time, so I declare my soundpool like that:
private SoundPool sp;
sp = new SoundPool(128, AudioManager.STREAM_MUSIC, 0);
After that I load all the MP3 sounds needed, about 80 sound of 55KB each. I have no troubles loading all the sounds, but its slow! Well it's no the problem. The real trouble is when I play about 20 sounds at the same time, there's an error in my log:
ERROR/AudioFlinger(59): no more track names available
ERROR/AudioTrack(26349): AudioFlinger could not create track, status: -12
ERROR/SoundPool(26349): Error creating AudioTrack
After that every sound that i try to play throws the same error, and no sound can be played. Not even sounds of another Activity / soundpool. I have no clue of what's going or how to fix it! Should I change the format of the sound files? Should I free memory or something after playing a sound?
(I'm testing on a Samsung Galaxy S I9000, 2.3.3 OS system. The app is 2.1)
see this (in android group)
For audio, there's a hard limit of 32 active AudioTrack objects per device (not per app:
you need to share those 32 with rest of the system),
A couple of thoughts here. One: the first parameter to the SoundPool constructor is not the number of sounds you want to load into it, it's the maximum number of simultaneous streams that you'll be playing. Second, SoundPool has limited memory for sounds, about 1MB. So I wouldn't be at all surprised if you hit some undocumented limit to the number of tracks you can load in at one time. Notice that 80 sounds times 55k per sound is definitely over 1MB. And that limit is for after the mp3s have been uncompressed into audio data inside SoundPool.

Android, load sounds and play immediately?

I have been attempting to play a bunch of sounds in my app as some views switch. The sound is narrative for the views and is between 3 and 10 seconds each, of which there are about 30.
First, I tried loading them all into a sound pool and passing it to a hashmap on program load, then I simply play them when required. This worked for the first 5 or 6 sounds but once I started to add more sounds to the sound pool, the later ones did not play. I assume this is due to the 1MB limit I have read about on soundpool.
I tried switching to just loading the sound and passing it straight to play on the next line however, no sounds play. Logcat just shows a reset and command cancelled for the player.
I switched then to loading the file and pointing to it with the hash map, however, even after doing an unload and loadimg a new sound at the same index it would just play the same sound every time.
I have tried MediaPlayer but it is ineffective for my desired application.
Can anyone suggest a way I should look to implement this properly? And should I be trying to load all sounds before hand or not?
I think you need to wait for the load to complete before you can play it. Add an onLoadCompleteListener and then play it when that is invoked.

Categories

Resources