playSound lag time


While students are working on their create apps in app lab, many of them are exploring some features that are not explicitly included in the lessons for CS Principles.

One example, a student is creating an app that concludes with a song being played. She uploaded MP3 files and her code works, but she experiences >20 second lag time between her event and the playback beginning. Lag time increases if she runs her app using a device with a slower processor, but when she uses her personal macbook pro (fastest processor we have tested with), she still gets >10 seconds lag time between the time a song should begin and the time the audio comes through the speakers. My class PC’s have slower processors and have even more lag time. I remember that last year a student had lag time between events and MP3 playback as well, but with much shorter lag times (despite having faster computers in my classroom this year).

In all cases, students are uploading their MP3’s to App Lab and using playSound() to initiate playback. Any help or guidance to reduce lag time is appreciated.




I’ve been unable to reproduce the problem on my 2015 Macbook Pro (no delay at all, as far as I can tell). I created a simple program to try it:

Let me know if the problem happen using the above program on the computer you’re using.

Also, would it be possible to post a link to an example of a program that has this problem? One that’s not a student’s Create task. I’m wondering if it could possibly be code related or maybe a delay caused by having to download the mp3 before playback.



The student is now experiencing minimal delay on her app. Three of her songs play almost immediately, one has about 1 second of lag. She says the one that has lag was the only file that she converted to mp3 using iMovie (the others were converted online from youtube links).

@frank_w_lee, when I run your app on my classroom computers, I get ~1 second lag before sound is coming out of the speakers. Maybe the issue has to do with the size of the mp3 file (quality settings, etc.)?