Skip to content

Steam Music ​

Steam has its own music player, and a player who is using it does not want your soundtrack on top of it. These calls read and control it, the same controls the Steam overlay shows.

Methods ​

isMusicEnabled() ​

Whether Steam Music is there to be controlled at all.

javascript
if (await steam.isMusicEnabled()) {
  // the player has Steam Music
}

isMusicPlaying() ​

Whether it is playing something right now.

getMusicPlaybackStatus() ​

0 undefined, 1 playing, 2 paused, 3 idle.

playMusic() / pauseMusic() ​

Play or pause the player's own music.

playPrevious() / playNext() ​

Back or on a track.

setMusicVolume(volume) / getMusicVolume() ​

The volume, 0 to 1.

javascript
await steam.setMusicVolume(0.3);

32-bit Windows

getMusicVolume() answers 0 in a 32-bit Windows build whatever the volume really is — a program of that width hands a decimal number back somewhere that cannot be read from. It is the only call in the whole API this happens to. A 64-bit Windows build answers properly.

Examples ​

Stay out of the way ​

javascript
async function startSoundtrack() {
  if (await steam.isMusicPlaying()) {
    // the player brought their own
    gameMusic.volume = 0;
    return;
  }
  gameMusic.volume = 1;
  gameMusic.play();
}

Duck their music in a cutscene ​

javascript
let restoreVolume = null;

async function beginCutscene() {
  if (!(await steam.isMusicPlaying())) return;
  restoreVolume = await steam.getMusicVolume();
  await steam.setMusicVolume(Math.min(restoreVolume, 0.1));
}

async function endCutscene() {
  if (restoreVolume !== null) {
    await steam.setMusicVolume(restoreVolume);
    restoreVolume = null;
  }
}

Controls in your own pause menu ​

javascript
document.querySelector('#next').onclick = () => steam.playNext();
document.querySelector('#prev').onclick = () => steam.playPrevious();
document.querySelector('#toggle').onclick = async () => {
  (await steam.isMusicPlaying()) ? steam.pauseMusic() : steam.playMusic();
};

Changes the player makes elsewhere arrive as musicPlaybackStatusChanged and musicVolumeChanged events, so a menu built this way can follow along instead of polling.