How I Fixed LibGDX Sounds Causing Game Lag on Android

• 2 min read

This post was last updated Jan 7, 2016 and may be out of date

tl;dr add silence to your sound files if they’re too short.

The release of my first ever mobile game Platform Pixels is coming up, so I’ve been testing it on as many devices as I can. I was confident after seeing it run on an old HTC One X (2012) but was saddened when I later saw it stutter on a more powerful Nexus 7 (2013). Then I noticed something. The stutter disappeared completely when I disabled the sound.

The framework that the game uses is libGDX so naturally I began searching for things like android libGDX audio lag to try to find a solution. Unfortunatly, there didn’t seem to be many people experiencing the same problem. This led me to believe that it was my fault, so I went through a few libGDX sound tutorials to be certain that I was doing everything correctly. I was.

Then, after about an hour more of debugging and searching, I came across this very understated Stack Overflow answer

Stack Overflow answer to audio lag

That’s it? Make the sounds longer? How could that possibly be a solution to the problem? It seemed like a troll answer since it only had one up vote and no comments, but I had tried everything else already and had no more ideas. So, I gave it a shot and it worked! I added a second of silence to the end of every sound and the stutter went away. I could finally relax in peace.

Thanks for reading, and I hope this saved you a lot of time if you had the same problem. If you have any thoughts or reasoning on the issue I would love to hear from you. If not, I guess I’ll just have to suffer eternally for not knowing. Thanks a lot Google.

Be the first to cheers
Now look what you've done 🌋
Stop clicking and run for your life! 😱
Uh oh, I don't think the system can't handle it! 🔥
Stop it, you're too kind 😄
Thanks for the love! ❤️
Thanks, glad you enjoyed it! Care to share?
HN Reddit

More Posts ✍🏻

See All »
• 6 min read • 80 votes
👆🏻 Creating a Pure CSS Dropdown Using the :hove...
Read Post »
• 4 min read • 1545 votes
💻 Wait for User to Stop Typing, in JavaScript
Read Post »
• 4 min read • 3814 votes
😈 Productive Procrastination
Read Post »
• 3 min read • 246 votes
✨ HTML Share Buttons
Read Post »
• 8 min read • 339 votes
🚜 A Simple Web Scraper in Go
Read Post »
• 6 min read • 86 votes
👔 Quit With Positivity
Read Post »
• 5 min read • 404 votes
🚀 Getting Over the Fear of Launching
Read Post »

Be the first to hear about posts, right in your inbox 💌