October 11, 2016
Sometimes failures are more interesting than successes. Last week marked the end of my focused efforts on the Gapless-5 library. Properly implemented, this library would enable a web jukebox to play multiple songs in order, without audible gaps in between the songs.
Web Browsers have two audio APIs. The first (the HTML5 Audio API) is intended for playing individual audio files, while the second (the Web Audio API) is focused on mixing and loading short clips into a buffer or effects-processing chain. Gapless-5 attempts to leverage the first API for playing the initial song, while using the second API to create a rolling buffer of subsequent songs.
Gapless-5 has an unfortunate litany of problems. One crucial issue relates to audible pops caused by inexact timing of the cutover between the two audio APIs. This issue is beyond fixable for me, since browser schedulers don’t treat audio as a priority in terms of service workers/timing. A second issue involves memory management — once Web Audio API buffers are created, browsers do a poor job at deallocating the memory these buffers have used. The only chance at garbage-collecting this data results in hitting a browser limit for the number of processing chains a webpage can initiate over time. Finally, the Web Audio API is poorly supported on mobile platforms such as iOS, which happily sleeps audio upon lock-screen activation, even in the middle of song playback.
Gapless playback is a nuance championed more by music purists than developers. As a result, the two APIs that might be extended to support gapless lack sufficient testing or engineering. It also works against Apple’s or Google’s interests to have their mobile browsers support high-quality audio playback outside the scope of their own Apple/Google Play stores. Mobile browsers frequently overstate their support of modern APIs, failing to mention their shortcomings versus the mature API implementations in desktop browsers.
Ironically, my biggest lesson is that it’s important to risk succeeding. The chances of Gapless-5 working in a high-quality way were always small, given the anti-competitive nature of mobile platforms. The flipside is basically the broken-window fallacy with a silver lining — although software platforms increase the cost of implementing a cross-platform project, if you’re skilled enough to push through the barriers, you’re likely to be in valuable, uncharted territory.