Index of every page on this site: llms.txt
All skills
oahc09 avatar

/cocosair-audio-video

@ed38648
by oahc09oahc09/cocosairjs3 stars
2
Run it yourself

Play media with AudioService, VideoPlayer and WebView. Use for silent autoplay, advancing currentTime, BGM/SFX channels or DOM video and iframe overlays.

  • 9 files
  • 40.4 KB
  • MIT
  • Updated last month
  • GitHub
Use this Skill: https://skilld.dev/gh/oahc09/cocosairjs/cocosair-audio-video

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencescommon-mistakes.md

≈886 tokens on demand. Your agent reads this file only when SKILL.md points to it.

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.

Common Mistakes

[HIGH] Trusting a playing boolean instead of the measured playback head

Wrong:

audio.playBgm('bgm');
console.log(audio.bgmState().playing);   // true even while the clock never advances

Correct:

const a = audio.bgmState().currentTime;
await new Promise((r) => setTimeout(r, 500));
const advanced = audio.bgmState().currentTime > a;   // real progress evidence

bgmState().currentTime is the measured clock (src/air/audio-service.ts:23-32, :199-204); the service header names this exact discipline (:8) and states that playback never unlocked by a gesture honestly shows as a non-advancing head (:10-12); playing only mirrors the backend state machine (src/cocos/audio/audio-source.ts:518-530), and pre-gesture ops are queued, not audibly started (src/cocos/audio/audio-source.ts:367-370, measured in docs/notes/audio-notes.md:51).

[HIGH] Mounting WebView on an active node before setting the url

Wrong:

const n = new Node('web'); n.addComponent(WebView); scene.addChild(n);  // __preload loads
n.getComponent(WebView).url = './page.html';                            // too late, second load

Correct:

const n = new Node('web'); n.active = false;
const wv = n.addComponent(WebView); wv.url = './page.html';             // set before preload runs
scene.addChild(n); n.active = true;

The default _url is https://cocos.com (src/cocos/web-view/web-view.ts:50) and __preload loads it unconditionally when the node activates (:168-179); docs/notes/webview-notes.md:37-51 measured the external first hit and prescribes inactive-create, set url, register listeners, then activate - listeners must be registered before addChild or the loading event is already gone.

[MEDIUM] Expecting sound before any user gesture

Wrong:

await createAirApp({ canvas: '#GameCanvas' });
audio.load('bgm', u).then(() => audio.playBgm('bgm'));   // no click yet: silent or queued

Correct:

document.addEventListener('click', () => { audio.playBgm('bgm'); }, { once: true });

The browser autoplay policy requires a gesture; the engine resumes the AudioContext on the first touchend/mouseup (src/pal/audio/web/player-web.js:104-111) and AudioSource.play() documents the two legal paths (src/cocos/audio/audio-source.ts:351-354). docs/manual/audio-video-webview.md:9-14 records the same for AIR, and a later DOM-audio track change may need a fresh gesture (:62).

[MEDIUM] Setting ENABLE_TRANSPARENT_CANVAS after the app is created

Wrong:

const app = await createAirApp({ canvas: '#GameCanvas' });
macro.ENABLE_TRANSPARENT_CANVAS = true;   // swapchain already built: stayOnBottom shows nothing
player.stayOnBottom = true;

Correct:

macro.ENABLE_TRANSPARENT_CANVAS = true;   // before createAirApp: alpha:true swapchain
const app = await createAirApp({ canvas: '#GameCanvas' });
player.stayOnBottom = true;               // video sinks under the canvas

The swapchain reads the flag once at creation (docs/notes/video-notes.md:34-35); the transparent path then zeroes the scene-side camera clear alpha (src/cocos/video/video-player-impl-web.ts:340-353), so proof is a document.elementFromPoint hit flip plus player.currentTime advance (docs/notes/video-notes.md:32-33).

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at ed38648. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last month
layer
subsystem
All 1 allowed tools
Read Edit Write Bash
Other metadata
compatibility
Cocos AIR source checkout or installed cocosair.js package. Browser rendering requires WebGL 2; source tooling requires Node.js >=18. Use the host-provided tools and user-authorized workspace.
when_to_use
[
  "audio starts silently before a user gesture",
  "control BGM and SFX channels or volume",
  "prove playback time actually advances",
  "place video above or below the canvas",
  "WebView mounts the wrong URL"
]
owns
[
  "audio-service",
  "autoplay-unlock",
  "playback-time",
  "video-player",
  "webview"
]
not_for
[
  "shared remote-file caching -> cocosair-assets",
  "DOM input geometry or HTML textures -> cocosair-graphics-and-dom",
  "keyboard and action focus -> cocosair-input-action"
]
metadata
{
  "author": "oahc09@gmail.com",
  "version": "1.0.0",
  "last-updated": "2026-10-13",
  "description_zh": "管理音频通道、用户手势解锁、播放证据、VideoPlayer 和 WebView。用于媒体加载、播放、平台限制或资源清理。"
}

README badge

README badge for oahc09/cocosairjs/cocosair-audio-video