vanilladocs
vanillapunch.com
API / core/audiomanager

core/audiomanager

오디오 매니저. 공유 AudioContext를 소유하며 AudioPlayer 생성을 담당한다. 브라우저 자동재생 정책 대응:

  • 첫 user gesture (click/touch/keydown) 전에 AudioContext 를 만들면 브라우저가 console 경고("AudioContext was not allowed to start ...")를 띄운다.
  • 그래서 AudioContext 는 lazy 생성 + user gesture 가 발생한 뒤에만 만든다.
  • resumeContext() 도 user gesture 이전에는 silently no-op 한다.
  • createAudioPlayer() 가 user gesture 전에 호출될 수 있는 경우를 위해 플레이어 생성 시점에는 (마지못해) AudioContext 를 만든다, 이때만 경고가 날 수 있음.

iOS 버전업 대응 (2026-10-22 03:41, iOS 26.6.2 에서 확인):

  • iOS 에서는 resumeContext() 로 복원된 컨텍스트가 "running" 이면 verifyContextClock() 으로 시계가 실제로 흐르는지 확인한다.
  • 옵션이 아니라 iOS(iPadOS 포함) 에서 늘 한다. 다른 플랫폼은 지금까지와 같다.

Audio manager. Owns the shared AudioContext and creates AudioPlayer instances. Handling the browser autoplay policy:

  • Creating an AudioContext before the first user gesture (click/touch/keydown) makes the browser print a console warning ("AudioContext was not allowed to start ...").
  • So the AudioContext is created lazily, only after a user gesture has happened.
  • resumeContext() also silently does nothing before a user gesture.
  • For the case where createAudioPlayer() is called before a user gesture, the AudioContext is created (reluctantly) when the player is created, and only then a warning may appear.

Handling iOS updates (2026-10-22 03:41, confirmed on iOS 26.6.2):

  • On iOS, when a context restored by resumeContext() is "running", verifyContextClock() checks that the clock is really advancing.
  • This is not an option: it always runs on iOS (including iPadOS). Other platforms behave as before.

AudioManagerextends Object

짝Counterpart: vanilla-engine AudioManager

오디오 매니저. 공유 AudioContext를 소유하며 AudioPlayer 생성을 담당한다. 브라우저 자동재생 정책 대응:

  • 첫 user gesture (click/touch/keydown) 전에 AudioContext 를 만들면 브라우저가 console 경고("AudioContext was not allowed to start ...")를 띄운다.
  • 그래서 AudioContext 는 lazy 생성 + user gesture 가 발생한 뒤에만 만든다.
  • resumeContext() 도 user gesture 이전에는 silently no-op 한다.
  • createAudioPlayer() 가 user gesture 전에 호출될 수 있는 경우를 위해 플레이어 생성 시점에는 (마지못해) AudioContext 를 만든다, 이때만 경고가 날 수 있음.

iOS 버전업 대응 (2026-10-22 03:41, iOS 26.6.2 에서 확인):

  • iOS 에서는 resumeContext() 로 복원된 컨텍스트가 "running" 이면 verifyContextClock() 으로 시계가 실제로 흐르는지 확인한다.
  • 옵션이 아니라 iOS(iPadOS 포함) 에서 늘 한다. 다른 플랫폼은 지금까지와 같다.

Audio manager. Owns the shared AudioContext and creates AudioPlayer instances. Handling the browser autoplay policy:

  • Creating an AudioContext before the first user gesture (click/touch/keydown) makes the browser print a console warning ("AudioContext was not allowed to start ...").
  • So the AudioContext is created lazily, only after a user gesture has happened.
  • resumeContext() also silently does nothing before a user gesture.
  • For the case where createAudioPlayer() is called before a user gesture, the AudioContext is created (reluctantly) when the player is created, and only then a warning may appear.

Handling iOS updates (2026-10-22 03:41, confirmed on iOS 26.6.2):

  • On iOS, when a context restored by resumeContext() is "running", verifyContextClock() checks that the clock is really advancing.
  • This is not an option: it always runs on iOS (including iPadOS). Other platforms behave as before.
예제Example오디오 플레이어와 버스 만들기Audio player and bus creation
import { Engine, EngineConfiguration, Scene } from "./build/vanilla.js";

class MainScene extends Scene {
	tick(timeDelta) {
		super.tick(timeDelta);
		const engine = this.getEngine();
		const audioManager = engine.getAudioManager();
		console.log(audioManager.hasUserGesture(), audioManager.getContextTime());
		const audioPlayer = audioManager.createAudioPlayer();
		const audioBus = audioManager.createAudioBus();
	}
}

const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());
생성자constructorconstructor(engine)#0.0.10 부터since 0.0.10소스source

생성.

Constructor.

engineEngine
소리를 맡을 엔진. (플랫폼 정보로 iOS 인지 가린다)The engine that owns the sound. (its platform information tells whether this is iOS)

짝Counterpart: vanilla-engine AudioManager.new

메서드methodmarkUserGesture()#0.2.1 부터since 0.2.1소스source

첫 user gesture 가 발생했음을 알린다. (Engine 의 click/touchstart/keydown 핸들러에서 호출)

Reports that the first user gesture happened. (called from the Engine's click, touchstart and keydown handlers)

짝Counterpart: vanilla-engine AudioManager.mark_user_gesture

메서드methodhasUserGesture()#0.2.1 부터since 0.2.1소스source

user gesture 이후인지 여부.

Whether this is after a user gesture.

반환Returnsboolean 첫 사용자 입력(클릭, 터치, 키)이 이미 있었으면 참.True if the first user input (click, touch, key) has already happened.

짝Counterpart: vanilla-engine AudioManager.has_user_gesture

메서드methodresumeContext()#0.0.10 부터since 0.0.10소스source

오디오 컨텍스트 재개.

  • user gesture 전에는 silently no-op (브라우저 경고 회피).
  • resume() 의 promise rejection 도 silently 처리.

Resumes the audio context.

  • Does nothing silently before a user gesture (avoids the browser warning).
  • Also handles a promise rejection of resume() silently.

짝Counterpart: vanilla-engine AudioManager.resume_context

메서드methodcreateAudioPlayer()#0.0.10 부터since 0.0.10소스source

오디오 플레이어 생성.

Creates an audio player.

반환ReturnsAudioPlayer 공유 오디오 컨텍스트로 만든 새 오디오 플레이어.A new audio player made with the shared audio context.

짝Counterpart: vanilla-engine AudioManager.create_audio_player

메서드methodcreateAudioBus()#0.4.0 부터since 0.4.0소스source

오디오 버스 생성. (AudioContext 가 없으면 만든다, 만들지 못하면 소리 없는 버스)

Creates an audio bus. (creates the AudioContext if there is none, a silent bus if it cannot be made)

반환ReturnsAudioBus 공유 오디오 컨텍스트로 만든 새 오디오 버스. (컨텍스트를 만들 수 없으면 소리 없는 버스)A new audio bus made with the shared audio context. (a silent bus if the context cannot be created)

짝Counterpart: vanilla-engine AudioManager.create_audio_bus

메서드methodgetContextTime()#0.4.0 부터since 0.4.0소스source

오디오 컨텍스트 시계. (초, audioContext.currentTime, AudioContext 가 없으면 0)

The audio context clock. (seconds, audioContext.currentTime, 0 if there is no AudioContext)

반환Returnsnumber 오디오 컨텍스트 시계. (초, 컨텍스트가 아직 없으면 0)The audio context clock. (seconds, 0 while there is no context yet)

짝Counterpart: vanilla-engine AudioManager.get_context_time

메서드methodgetAudioContext()#0.0.10 부터since 0.0.10소스source

오디오 컨텍스트 반환. (없으면 null)

Returns the audio context. (null if there is none)

반환ReturnsAudioContext | null 공유 오디오 컨텍스트. (아직 만들지 않았으면 null)The shared audio context. (null if not created yet)

짝Counterpart: vanilla-engine AudioManager.get_audio_context