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?
Related
I'm trying to loop a ~30 seconds audio track multiple times. I'm using a MediaPlayer to play the sounds, here is the code where its created:
mAnimalMediaPlayer = MediaPlayer.create(mContext, fish.getSound());
I then call:
mAnimalMediaPlayer.setLooping(true);
mAnimalMediaPlayer.start();
when a play button is clicked. When the track loops, there is a small but noticeable pause between the track ending and the new loop beginning. I am positive that the audio file im using does not contain any actual pause.
Here is an android bug report which has been up for some time: https://code.google.com/p/android/issues/detail?id=18756
I've tried a few workarounds (such as using .ogg files instead of .mp3) but the problem persists.
I'm looking for any possible workaround that will allow me to seamlessly loop the playback multiple times.
There is a very noticeable pause. However, I have just discovered through experimentation on an emulator running level 25 that if one prepares two identical players and alternately starts them one after the other when the other has finished then the gap becomes much more difficult to hear.
their are some questions on stackoverflow about looping sound in android but neither gave me correct answer so i start new thread,
I want to loop a sound without gaps in android. I tried to use the code mediaplayer.setLooping(true) for mp3,ogg and wav file to loop the sound, but there is always a little pause when the first sound is over and the next sound start..my audio length is 2 min. and file size is more than 1 mb so i cant use soundpool for repeating sound.
i didn't know how to solve this issue.
Ok basically you have to create two objects of media player and then if time of first music is going to b finished then call the other one and your problem is solver
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
i understand that there are some issues why android can't ply low latency audio and has a >100ms delay on everything (well.. actually vibrations are faster as audio!!! Shame on you!).. but is there some possibility to figure out how much earlier i need to run the sound to actually be on time?
e.g. how to calculate audio delay?
Im creating a rhythm game and i need to play "ticks" in sync with music.
Im using libGDX Sound - e.g. sound pool - play() now.
Any suggestions?
Your app could emit a sound with the speaker and then use the microphone to detect the sound emited by itself (something similar to remote.js).
Even though there are many variables involved (the mic will also have a latency), you can make the device calibrate it self by continuously trying to guess how long the sound will take to be detected, and emiting it again and again until your guess gets "fine tuned".
I am making a game for android which needs to play a small beep whenever a user touches a certain object.
To do this I have this simple code to create the media player. beep is a small .ogg file of ~1.5 sec length.
MediaPlayer mp = MediaPlayer.create(getContext(), R.raw.beep);
mp.setVolume(0.5f, 0.5f);
and use it like this
mp.start();
The problem I am having is that my game uses the android canvas, and the thread which draws to the canvas also calls mp.start(). I have discovered that playing the sound is taking quite a lot of time, and it is very varied in how long it takes. Sometimes 1ms, sometimes 15ms. This appears to be causing my game to noticeably lag a little bit, as the android canvas is pretty slow anyway.
I've had a look at the logs and I don't appear to having garbage collection causing the delay. I'm wondering if anyone can give me some advice to reduce this delay
EDIT - I've just discovered that MediaPlayer is designed for longer sound files, and SoundPool is better for shorter audio files. However, I load the file into the mediaPlayer only once, so I don't see how it should make any difference. I will test it out though
sorry for my english
Use SoundPool instead of MediaPlayer cause MediaPlayer need releasing memory after each call or call method mp.release() after each call of player
SoundPool tutorial here