Derived from the cocosair-audio-video skill and its canonical docs/source pointers; reorganized on 2026-10-11. Source annotations below identify repository inputs, not files guaranteed to ship to npm consumers.
Contracts
AudioServicesurface is exactly:load(src/air/audio-service.ts:67,assetManager.loadRemoteat:71),playBgm(:108, throws for an unloaded id:110, pauses other channels:111-113),pauseBgm(:120),stopBgm(:126, zeroes the head, keeps the id),setBgmVolume(:132,RangeErrorcodeAIR_E_AUDIO_VOLUME:134-136),resumeBgm(:145, continues from the preserved head),playSfx(:155),setMusicEnabled(:185, pauses BGM when off),setSfxEnabled(:191),bgmState(:199),dispose(:207), plus gettersbgmId/musicEnabled/sfxEnabled/sfxActive(:97-101).- The SFX cap is real: option
maxSfxVoicesdefaults to 5 (src/air/audio-service.ts:61), overflow fires incrementsfxDroppedand are dropped, never queued (:159); a voice frees its slot onAudioSource.EventType.ENDED(:175) with a boundedsetTimeoutfallback because autoplay rejection may emit no event (:177-179). bgmState()returns{ id, playing, currentTime, loop, volume }andcurrentTimeis the measured clock (src/air/audio-service.ts:23-32,:199-204); the header comment records the discipline "playing=true alone does not prove the clock advances" (:8).- Gesture unlock is a browser+PAL contract: the engine resumes the AudioContext on the first
touchend/mouseupcapture (src/pal/audio/web/player-web.js:104-111, DOM-audio pathsrc/pal/audio/web/player-dom.js:46-54);AudioSource.play()documents that pre-gesture plays may be queued or rejected (src/cocos/audio/audio-source.ts:351-354), and pending ops are held until the clip loads (:367-370). AudioSourceevents areSTARTED='started'andENDED='ended'on the node (src/cocos/audio/audio-source.ts:36-39,:69, emitted:165-167,:380-381);currentTimeget/set (:480-500),duration(:508),state(:518),playing(:528),playOneShot(:430).VideoPlayerevents aremeta-loaded,ready-to-play,playing,paused,stopped,completed,error,clicked(src/cocos/video/video-player-enums.ts:48-95), bridged from the<video>element in__preload(src/cocos/video/video-player.ts:395-414);ResourceType.REMOTE|LOCAL(src/cocos/video/video-player-enums.ts:31-46) withplay/resume/pause/stop(src/cocos/video/video-player.ts:492-533) andcurrentTime/duration/state/isPlaying/nativeVideo(:311-372).- Video is a DOM overlay:
<video class="cocosVideo">is appended togame.container(src/cocos/video/video-player-impl-web.ts:258-278) and positioned by a CSS matrix each frame (src/cocos/video/video-player.ts:435-439); transparent layering viastayOnBottom(src/cocos/video/video-player.ts:277-288) setsz-index:-32768(src/cocos/video/video-player-impl-web.ts:228-234) and zeroes the scene-side camera clear alpha (:340-353), which requiresmacro.ENABLE_TRANSPARENT_CANVASbeforecreateAirApp(src/cocos/core/platform/macro.ts:984, example usageexamples/video-basic/main.js:64). WebViewevents areloading,loaded,error(src/cocos/web-view/web-view-enums.ts:25-46),nativeWebViewis theHTMLIFrameElement(src/cocos/web-view/web-view.ts:99-101),evaluateJSrunscontentWindow.eval(:162-166,src/cocos/web-view/web-view-impl-web.ts:116-128);setJavascriptInterfaceSchemeandsetOnJSCallbackare no-ops that warn on Web (src/cocos/web-view/web-view-impl-web.ts:130-136).- All six symbols (
AudioService,AudioSource,AudioClip,VideoPlayer,VideoClip,WebView) are in the single export block ofbuild/cocosair.module.js(currently :161574);AudioServicereaches it throughsrc/air/index.ts:27. Video and WebView capabilities remain browser-limited: codecs are the browser's, the iframe never enters the WebGL frame buffer, and webkit may pause small videos at the end (docs/notes/video-notes.md:89-98).