playAudio

View sourceplayAudio(world: World): void

Drives AudioPlayer components from the world’s typed audio assets.

AudioPlugin registers this exact function in AppSchedule.Update. Each update looks up AudioGraph and AudioAssets, then queries only entities that have both an AudioPlayer and a Timer using Query#each. Players without a handle or whose handle is not currently resolved are skipped. The system does not load audio or process a player without a timer.

For a resolved player without a graph slot, the system reserves an empty AudioGraph slot, connects it to attach or the graph root, and sets the timer duration from the decoded buffer before restarting the timer while preserving its current elapsed position. On a later playback change, it creates an AudioBufferSourceNode with the buffer and timer speed. The loop flag is false for TimerMode.Once and true for TimerMode.Repeat; other numeric modes fall back to false. The node starts at the timer’s elapsed offset and replaces the placeholder through AudioGraph#update.

A paused timer clears the current native source. A completed timer is also cleared before the system checks for a playback change. If no playback change is reported, the existing source is left alone. Replacing or clearing a graph slot lets AudioGraph stop and disconnect the previous native source while retaining the slot and its outgoing edge.

Examples

import { AudioAssets, AudioPlayer } from '@wimaengine/audio'
import { Timer } from '@wimaengine/time'

// AudioPlugin registers playAudio in the Update schedule.
function inspectPlayer(world, entity) {
  const player = world.get(entity, AudioPlayer)
  const audio = player.audio
    ? world.getResource(AudioAssets).get(player.audio)
    : undefined
  const timer = world.get(entity, Timer)

  console.log(audio?.audiobuffer.duration, timer?.elapsed())
}

Parameters

NameDescriptionDefault
world

World containing the audio resources and entities.

—