Server playback and audiences
One server Audio object gives its listeners a shared playback timeline. Create
separate objects when players need independent playback, such as a briefing that
each player starts at a different time.
Play to selected players
Section titled “Play to selected players”Place briefing.ogg under audio/ in the client content root. This example starts
a briefing for a group of players:
// @ts-check/// <reference types="@revomp/types-server" />import * as revo from 'revo-server';
/** @param {readonly revo.Player[]} participants */function startBriefing(participants) { const briefing = new revo.Audio('resources://audio/briefing.ogg', { volume: -6, });
briefing.clearPlayers(); for (const player of participants) { briefing.addPlayer(player); }
briefing.play(); return briefing;}Call startBriefing(participants) when the briefing begins and retain the
returned object to control it. The sound has no pos, so its listeners can hear
it across distances and dimensions. Spatial sounds also follow the
distance, dimension and attachment rules.
Change the audience
Section titled “Change the audience”New audio uses everyone mode, which includes players who connect later. Use an explicit list to limit playback to a team, activity or individual player.
| Method | Effect |
|---|---|
clearPlayers() |
Switches to an empty explicit list. |
addPlayer(player) |
Adds a player to the explicit list. From everyone mode, switches to a list containing that player. |
removePlayer(player) |
Removes a player from the explicit list. Has no effect in everyone mode. |
setEveryone() |
Restores everyone mode and clears the explicit list. |
hasPlayer(player) |
Checks audience membership. |
Read everyone to check which mode is active. To exclude someone from a sound
heard by everyone, build an explicit list of the players who should hear it.
hasPlayer() checks membership only. Spatial streaming, loading and listener
settings determine whether the sound is audible.
Removing listeners leaves the shared timeline running, even when the list is empty. Explicit membership belongs to the current player connection. Add a reconnecting player again if they should rejoin the audience.
Late listeners
Section titled “Late listeners”Adding a player during playback joins them at the current position. For example,
a player added 30 seconds after play() joins around 30 seconds into the
recording. Loading and buffering can delay when they hear it.
Use addPlayer() alone when someone joins an existing audience. Calling play()
again restarts the sound for everyone. A paused sound stays paused for new
listeners until resume() is called.
The server’s playbackPosition is measured in seconds and continues increasing
across loops. Listeners use the corresponding position within the recording.
Live sources join the current broadcast and report 0 for playbackPosition.
Control playback
Section titled “Control playback”These controls affect every listener of the object:
| Method | Effect for a recording |
|---|---|
play() |
Starts or restarts playback from zero. |
pause() |
Saves the current position and pauses. Returns false unless playback was playing. |
resume() |
Continues from the paused position. Returns false unless playback was paused. |
seek(seconds) |
Changes the position while preserving the playing, paused or stopped state. |
stop() |
Stops playback and resets the position, retaining the object and audience. |
To start at an offset, call play() followed by seek(seconds). Calling play()
after seek() resets the position to zero. Set loop = true to repeat a recording.
Live sources reject seeking and looping, and resuming reconnects to the broadcast.
For recorded HTTP sources, see the
seeking caveat.
state reflects server commands. Loading, buffering, failures and natural
completion are tracked on each client through the
audio events. A failure
on one client leaves the other listeners’ playback running.
Keep the object if it will be played again. When the activity ends, call
destroy() to stop playback for its listeners and release it.