- Home /
AudioSource.Play lags.
I'm working on an Android app where audio needs to be played when the user touches the screen. The problem is that there is a slight delay between the touch and the actual audio starting even though play is called in the same frame that the touch is registered. the delay seems to be anywhere from 2-7 frames worth and it's not a consistent delay. I've tried changing the DSP buffer size down to 512x2 which is the lowest I can go without distorting the audio. Also using decompressed audio files doesn't seem to help. there are a lot of audio files so keeping them compressed is ideal.
Has anyone else had this issue and what workarounds or fixes could be implemented?
:edit: I have tested other non unity android apps on the same device that have less lag.
Have you solved the problem? Been trying to fix this for days and now i'm stock. Because of this, i cant make improvements on my first game T_T please reply
Answer by zakirshikhli · Dec 29, 2019 at 04:34 PM
I fixed music lag issue by swtiching this setting: Player Settings -> Project Settings -> Audio -> DSP Buffer Size -> choose Best Performance. When I selected "best latency", lag becomes even worst. (My device is Redmi 7A on Miui 11 Global). Leave other Audio settings as is (reset to default)
I also selected "decompress on load" + "preload audio data" for bg music files.
Answer by tanoshimi · Dec 09, 2014 at 06:34 PM
Audio lag on Android is a known issue, and one that varies in severity from device to device (see here for an article from Google I/O presentation on the subject, and if you search here on UA you'll find several posts on the topic).
MP3s certainly always feature a decompression lag, so you'll want to keep your clips as uncompressed WAV. Are you playing the audio using PlayOneShot? That's also inefficient - you should probably have a pool of instantiated AudioSources and just load in the appropriate clip.
You already mention you've reduced the buffer size. Other than that, I'm not sure there is a concrete solution :(
Thanks for the quick response.
I have AudioSources on several object that play the sounds and they are preloaded with the audio clips they need in the editor. I'm not using play one shot nor loading the clips dynamically anywhere. I'm aware that android has issues but for some reason other (non unity) apps have a much smaller delay that what my app is experiencing on the same device.
I will try decompressing the files and see if that has some relevant change on the delay with the updates I've been making, unfortunately this makes the AP$$anonymous$$ size on the "too big" side.
Your answer
Follow this Question
Related Questions
Passing audio information from unity to third-party 0 Answers
AudioClip huge lag on some android devices 0 Answers
Audio from Video starts stuttering + video playback lag after a few minutes 0 Answers
Playing each channel of a midi track on separate audio sources? 0 Answers
[NoBraves] Sound makes lag 1 Answer