Music sets the tone of a loading screen, and it's also easy to get wrong: players join and hear nothing, or they get a track at full volume. GMod's embedded browser lets audio start without a click, so most problems come from the file, the format or the volume.
Why autoplay works in GMod but not in Chrome
Desktop browsers block audio until the user interacts with the page. In GMod, the loading screen can start audio without a click. That matters, because the player can't click at all: GMod turns off mouse input on the loading panel (lua/menu/loading.lua).
Formats that play
- MP3: the usual choice for GMod's Chromium 86 on Windows, and the format Lumescreen uses. 128 to 192 kbit/s is plenty for a loading screen.
- OGG Vorbis: also plays, and many older templates use it. Some Linux players still run GMod's older Awesomium engine (GMod wiki), so test OGG as well if they matter to you.
- WAV: plays, but a 3-minute WAV is over 30 MB, several times the size of the same track in MP3. Convert it.
- M4A and AAC: avoid them. AAC is a proprietary codec and the GMod tracker lists the MP4 format as unsupported (issue #3148). Convert to MP3 or OGG.
- YouTube and Spotify: YouTube embeds don't play in GMod (issue #5644), and Spotify only plays full tracks for a logged-in listener. Host a plain audio file instead.
A minimal example
<audio id="music" src="https://cdn.example.com/music.mp3" loop></audio>
<script>
var music = document.getElementById("music");
var baseVolume = 0.35; // start quiet
music.volume = baseVolume;
var playing = music.play();
if (playing && playing.catch) {
// In a desktop browser preview, autoplay may be blocked: wait for a click.
playing.catch(function () {
document.addEventListener("click", function () { music.play(); }, { once: true });
});
}
// GMod passes the player's music volume (0 to 1) as the 7th argument.
window.GameDetails = function (servername, serverurl, mapname, maxplayers,
steamid, gamemode, volume) {
if (typeof volume === "number") {
music.volume = baseVolume * volume;
}
};
</script>The starting volume is deliberately low. The loop attribute covers downloads that outlast the track. The .catch() fallback only matters in a desktop browser, where autoplay is blocked.
Respect the player's music volume
There is no mute button on a GMod loading screen, since players can't click. What you can do is follow their settings: since April 2023, GMod passes the player's music volume (snd_musicvolume, from 0 to 1) to GameDetails. A player who set music to 0 in GMod expects silence. Multiply your volume by that value, as in the example above.
Common mistakes
- Audio over plain HTTP on an HTTPS page: mixed content is blocked and the player hears nothing. Serve the file over https.
- Very high bitrates: the player's connection is busy downloading your server's content at the same time. A 128 to 192 kbit/s MP3 starts sooner than a lossless file.
- No loop, no playlist: a 90-second track on a 4-minute first join leaves silence while the player is still waiting.
- Copyright-flagged tracks: your loading screen is public. Use licensed or royalty-free music, especially if the server is promoted on YouTube.
The zero-code way
Every Lumescreen theme can play music. Upload an MP3, OGG or WAV in the dashboard: Lumescreen converts it to MP3 (192 kbit/s, or 128 kbit/s for very long tracks), stores it and starts it automatically in game. There is no mute button in game, so pick a calm track and keep its level moderate. Set sv_loadingurl once (see the installation guide) and you're done.