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.

referencesvideoplayer.md

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

Derived from src/cocos/video/video-player.ts, src/cocos/video/video-player-enums.ts, src/cocos/video/video-player-impl-web.ts, src/cocos/video/video-player-impl.ts, src/cocos/video/video-downloader.ts, src/cocos/video/assets/video-clip.ts, src/cocos/core/platform/macro.ts, examples/video-basic/main.js, docs/manual/audio-video-webview.md, docs/notes/video-notes.md, build/cocosair.module.js (as of 2026-10-10).

What VideoPlayer is on Web

VideoPlayer (src/cocos/video/video-player.ts:51) requires a UITransform (:49) and, on Web, appends a real <video class="cocosVideo"> element to game.container (src/cocos/video/video-player-impl-web.ts:258-278) - the pixels never enter the WebGL frame buffer, and each frame the component pushes its node world matrix through the UI camera into a CSS matrix() transform on the element (src/cocos/video/video-player.ts:435-439, src/cocos/video/video-player-impl-web.ts:331-422). Codec support, autoplay behavior and end-of-file quirks belong to the browser: webkit keeps readyState at 3 in the measured matrix and pauses small videos at the end (docs/notes/video-notes.md:89-100, docs/notes/video-notes.md:120-139). VideoPlayer and VideoClip are on the bundle export list (build/cocosair.module.js, currently :161574).

Resource selection and source switching

resourceType is VideoPlayer.ResourceType.REMOTE (0) or LOCAL (1) (src/cocos/video/video-player-enums.ts:31-46, statics on the component src/cocos/video/video-player.ts:291); setting remoteURL or clip re-runs syncSource (:94-134, :374-393), which removes the old element and rebuilds it - syncClip/syncURL both call removeVideoPlayer first (src/cocos/video/video-player-impl-web.ts:114-124), and LOCAL uses clip.nativeUrl (:117). The LOCAL branch loads through VideoClip (src/cocos/video/assets/video-clip.ts) with the video downloader registered in src/cocos/video/video-downloader.ts. play/resume/pause/stop forward to the element wrapper (src/cocos/video/video-player.ts:492-533, src/cocos/video/video-player-impl-web.ts:73-112); stop sets currentTime = 0, pauses, and dispatches stopped on the next tick (:101-112).

Event surface

VideoPlayer.EventType (src/cocos/video/video-player.ts:290) is the string enum none, playing, paused, stopped, completed, meta-loaded, ready-to-play, error, clicked (src/cocos/video/video-player-enums.ts:48-95). __preload binds the DOM element events (loadedmetadata, canplay, play, playing, pause, click, ended, error - src/cocos/video/video-player-impl-web.ts:280-291) to those names and re-emits them on the node and through the serialized videoPlayerEvent handler list (src/cocos/video/video-player.ts:395-414, per-event emitters :441-480, handler array :303). state returns the last dispatched event name (:358-361), so ready-to-play is the load gate the example waits on before trusting duration (docs/manual/audio-video-webview.md:77). playOnAwake fires play() from ready-to-play (src/cocos/video/video-player.ts:142-148, :411-413, :446-450), and the element play() promise rejection on an ungestured page is caught silently - the head simply does not advance (src/cocos/video/video-player-impl-web.ts:73-88).

Playback evidence

Use currentTime (src/cocos/video/video-player.ts:321-339, backed by the element property src/cocos/video/video-player-impl-web.ts:161-166) plus isPlaying (src/cocos/video/video-player.ts:369-372), and wait for settled state rather than wall-clock: a paused seek also moves the head, so frame-decode proof needs drawImage pixel statistics with isPlaying confirmed first (docs/notes/video-notes.md:83-87). Seeking beyond duration clamps and pauses without emitting completed (docs/notes/video-notes.md:111-118); a seek near the file end combined with loop can race the loop restart on webkit and park the element paused (docs/notes/video-notes.md:120-139), so wait for nativeVideo.seeking === false before asserting wrap-around.

Transparent video (stayOnBottom)

stayOnBottom is Web-only and depends on canvas translucency (src/cocos/video/video-player.ts:266-288). It does two things: pushes the element to z-index: -32768 (src/cocos/video/video-player-impl-web.ts:228-234) and, on the next syncMatrix, sets the alpha of the scene-side batcher camera clear color to 0 and forces a full clear (:340-353; that camera is not the component's camera - docs/notes/video-notes.md:20-31). For this to show anything, macro.ENABLE_TRANSPARENT_CANVAS = true must be set before createAirApp, because the swapchain reads it once (src/cocos/core/platform/macro.ts:984, examples/video-basic/main.js:64, docs/notes/video-notes.md:34-35). Proof is a document.elementFromPoint hit flipping from VIDEO to CANVAS plus the scene-side clear alpha reading 0 (docs/notes/video-notes.md:28-33).

Fullscreen honesty

fullScreenOnAwake set before the clip is assigned takes the geometric path - syncMatrix stretches the element to visibleRect without any requestFullscreen (src/cocos/video/video-player.ts:247-264, docs/notes/video-notes.md:72-74, docs/manual/audio-video-webview.md:80-82). Setting it after load routes into canFullScreen, which early-exits unless readyState === 4 (src/cocos/video/video-player-impl-web.ts:175-226), passes the target element to a chain that ultimately requests fullscreen on document.body (measured fullscreenElement === BODY, docs/notes/video-notes.md:43-48), and has a registered defect chain (F-103) including a shadowed-document callback that logs a console error (docs/notes/video-notes.md:49-60). The reliable interactive path is calling await screen.requestFullScreen() / await screen.exitFullScreen() yourself inside a gesture (docs/notes/video-notes.md:66-71).

Lifecycle and leak counting

removeVideoPlayer detaches the element only when it is actually a child of game.container and clears listeners there (src/cocos/video/video-player-impl-web.ts:243-256), so the count of <video class="cocosVideo"> nodes in the DOM is the real leak counter: after node.destroy() the count must drop (docs/notes/video-notes.md:78-80). onDestroy releases the impl (src/cocos/video/video-player.ts:428-433); disabling the component pauses and hides the element (src/cocos/video/video-player-impl-web.ts:318-329). keepAspectRatio toggles object-fit intent but the engine positions by matrix, and the measured element always reports none across engines (docs/notes/video-notes.md:102-104).

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