A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(audio): a cooked mini-game plays the file the package carries
esengine71ab1ab6a834
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex fb81dec8b..649c76102 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -14,6 +14,18 @@ published separately; it ships inside the editor.## [Unreleased]+### Fixed++- **A cooked mini-game plays its sound effects.** The cook re-encodes `tap.wav` to+ `assets/<hash>.mp3`, and a mini-game player is handed a URL rather than bytes — but+ the asset loader handed it the AUTHORED path, which is the cache key, not a file the+ package carries. Every preloaded clip pointed at a name that no longer existed, so an+ uploaded WeChat build was silent (#59).++ A backend now declares what it needs to play a clip (`PlatformAudioBackend.delivery`:+ `bytes` or `url`), the resolved source is what reaches it, and a `url` backend is no+ longer made to wait on a fetch whose bytes it then drops.+## [0.64.0] - 2026-09-12### Addeddiff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.mdindex 5a1569c22..eb8b6f902 100644--- a/sdk/etc/index.api.md+++ b/sdk/etc/index.api.md@@ -1,7 +1,7 @@# API surface — esengine/index<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 114 public · 94 beta · 1681 experimental · 3 deprecated+Symbols: 114 public · 94 beta · 1682 experimental · 3 deprecated## ABI_LAYOUT_HASH — const @experimental```@@ -976,6 +976,7 @@ ResourceDef<AudioAPI>```baseUrl: stringbufferBudget: number+delivery: AudioDeliverydispose: () => voidensureBus: (name: string, parent?: string) => booleangetBufferHandle: (url: string) => AudioBufferHandle | undefined@@ -1079,6 +1080,11 @@ parent: string | undefinedvolume: number | undefined```+## AudioDelivery — type @experimental+```+'bytes' | 'url'+```+## AudioHandle — interface @experimental```currentTime: number@@ -2029,14 +2035,14 @@ before: numberdelta: numberkey: stringtier: CensusTier-unit: "count" | "bytes"+unit: "bytes" | "count"```## CensusEntry — interface @experimental```key: stringtier: CensusTier-unit: "count" | "bytes"+unit: "bytes" | "count"value: number```@@ -2081,7 +2087,7 @@ reason: string | undefinedrisingFraction: numberslopePerCycle: numbertier: CensusTier-unit: "count" | "bytes"+unit: "bytes" | "count"```## ChainCollider2D — const @experimental@@ -6137,13 +6143,14 @@ writeCacheFile: ((key: string, bytes: ArrayBuffer) => Promise<void>) | undefined## PlatformAudioBackend — interface @experimental```+delivery: AudioDeliverydispose: () => voidensureResumed: () => Promise<void>getFrequencyData: ((out: Uint8Array) => boolean) | undefinedinitialize: (options?: AudioBackendInitOptions) => Promise<void>isReady: boolean-loadBuffer: (url: string) => Promise<AudioBufferHandle>-loadBufferFromData: (url: string, data: ArrayBuffer) => Promise<AudioBufferHandle>+loadBuffer: (src: string) => Promise<AudioBufferHandle>+loadBufferFromData: (src: string, data: ArrayBuffer) => Promise<AudioBufferHandle>mixer: AudioMixer | nullname: stringplay: (buffer: AudioBufferHandle, config: PlayConfig) => AudioHandlediff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.mdindex a590ce1ad..3247f1c21 100644--- a/sdk/etc/index.native.api.md+++ b/sdk/etc/index.native.api.md@@ -1,7 +1,7 @@# API surface — esengine/index.native<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 114 public · 99 beta · 1700 experimental · 3 deprecated+Symbols: 114 public · 99 beta · 1701 experimental · 3 deprecated## ABI_LAYOUT_HASH — const @experimental```@@ -976,6 +976,7 @@ ResourceDef<AudioAPI>```baseUrl: stringbufferBudget: number+delivery: AudioDeliverydispose: () => voidensureBus: (name: string, parent?: string) => booleangetBufferHandle: (url: string) => AudioBufferHandle | undefined@@ -1079,6 +1080,11 @@ parent: string | undefinedvolume: number | undefined```+## AudioDelivery — type @experimental+```+'bytes' | 'url'+```+## AudioHandle — interface @experimental```currentTime: number@@ -2029,14 +2035,14 @@ before: numberdelta: numberkey: stringtier: CensusTier-unit: "count" | "bytes"+unit: "bytes" | "count"```## CensusEntry — interface @experimental```key: stringtier: CensusTier-unit: "count" | "bytes"+unit: "bytes" | "count"value: number```@@ -2081,7 +2087,7 @@ reason: string | undefinedrisingFraction: numberslopePerCycle: numbertier: CensusTier-unit: "count" | "bytes"+unit: "bytes" | "count"```## ChainCollider2D — const @experimental@@ -6320,13 +6326,14 @@ writeCacheFile: ((key: string, bytes: ArrayBuffer) => Promise<void>) | undefined## PlatformAudioBackend — interface @experimental```+delivery: AudioDeliverydispose: () => voidensureResumed: () => Promise<void>getFrequencyData: ((out: Uint8Array) => boolean) | undefinedinitialize: (options?: AudioBackendInitOptions) => Promise<void>isReady: boolean-loadBuffer: (url: string) => Promise<AudioBufferHandle>-loadBufferFromData: (url: string, data: ArrayBuffer) => Promise<AudioBufferHandle>+loadBuffer: (src: string) => Promise<AudioBufferHandle>+loadBufferFromData: (src: string, data: ArrayBuffer) => Promise<AudioBufferHandle>mixer: AudioMixer | nullname: stringplay: (buffer: AudioBufferHandle, config: PlayConfig) => AudioHandlediff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.mdindex 74b97b57b..90a627e7b 100644--- a/sdk/etc/index.node.api.md+++ b/sdk/etc/index.node.api.md@@ -1,7 +1,7 @@# API surface — esengine/index.node<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 114 public · 96 beta · 1680 experimental · 3 deprecated+Symbols: 114 public · 96 beta · 1681 experimental · 3 deprecated## ANCHOR_AXES — const @experimental```@@ -971,6 +971,7 @@ ResourceDef<AudioAPI>```baseUrl: stringbufferBudget: number+delivery: AudioDeliverydispose: () => voidensureBus: (name: string, parent?: string) => booleangetBufferHandle: (url: string) => AudioBufferHandle | undefined@@ -1074,6 +1075,11 @@ parent: string | undefinedvolume: number | undefined```+## AudioDelivery — type @experimental+```+'bytes' | 'url'+```+## AudioHandle — interface @experimental```currentTime: number@@ -2024,14 +2030,14 @@ before: numberdelta: numberkey: stringtier: CensusTier-unit: "count" | "bytes"+unit: "bytes" | "count"```## CensusEntry — interface @experimental```key: stringtier: CensusTier-unit: "count" | "bytes"+unit: "bytes" | "count"value: number```@@ -2076,7 +2082,7 @@ reason: string | undefinedrisingFraction: numberslopePerCycle: numbertier: CensusTier-unit: "count" | "bytes"+unit: "bytes" | "count"```## ChainCollider2D — const @experimental@@ -6132,13 +6138,14 @@ writeCacheFile: ((key: string, bytes: ArrayBuffer) => Promise<void>) | undefined## PlatformAudioBackend — interface @experimental```+delivery: AudioDeliverydispose: () => voidensureResumed: () => Promise<void>getFrequencyData: ((out: Uint8Array) => boolean) | undefinedinitialize: (options?: AudioBackendInitOptions) => Promise<void>isReady: boolean-loadBuffer: (url: string) => Promise<AudioBufferHandle>-loadBufferFromData: (url: string, data: ArrayBuffer) => Promise<AudioBufferHandle>+loadBuffer: (src: string) => Promise<AudioBufferHandle>+loadBufferFromData: (src: string, data: ArrayBuffer) => Promise<AudioBufferHandle>mixer: AudioMixer | nullname: stringplay: (buffer: AudioBufferHandle, config: PlayConfig) => AudioHandlediff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.mdindex fe66f7249..7da4c36f0 100644--- a/sdk/etc/minigame.api.md+++ b/sdk/etc/minigame.api.md@@ -1,7 +1,7 @@# API surface — esengine/minigame<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 114 public · 94 beta · 1702 experimental · 3 deprecated+Symbols: 114 public · 94 beta · 1703 experimental · 3 deprecated## ANCHOR_AXES — const @experimental```@@ -971,6 +971,7 @@ ResourceDef<AudioAPI>```baseUrl: stringbufferBudget: number+delivery: AudioDeliverydispose: () => voidensureBus: (name: string, parent?: string) => booleangetBufferHandle: (url: string) => AudioBufferHandle | undefined@@ -1074,6 +1075,11 @@ parent: string | undefinedvolume: number | undefined```+## AudioDelivery — type @experimental+```+'bytes' | 'url'+```+## AudioHandle — interface @experimental```currentTime: number@@ -2024,14 +2030,14 @@ before: numberdelta: numberkey: stringtier: CensusTier-unit: "count" | "bytes"+unit: "bytes" | "count"```## CensusEntry — interface @experimental```key: stringtier: CensusTier-unit: "count" | "bytes"+unit: "bytes" | "count"value: number```@@ -2076,7 +2082,7 @@ reason: string | undefinedrisingFraction: numberslopePerCycle: numbertier: CensusTier-unit: "count" | "bytes"+unit: "bytes" | "count"```## ChainCollider2D — const @experimental@@ -5098,12 +5104,13 @@ toVersion: string## MiniGameAudioBackend — class @experimental```+delivery: "url"dispose: () => voidensureResumed: () => Promise<void>initialize: (_options?: AudioBackendInitOptions) => Promise<void>isReady: boolean-loadBuffer: (url: string) => Promise<AudioBufferHandle>-loadBufferFromData: (url: string, _data: ArrayBuffer) => Promise<AudioBufferHandle>+loadBuffer: (src: string) => Promise<AudioBufferHandle>+loadBufferFromData: (src: string, _data: ArrayBuffer) => Promise<AudioBufferHandle>mixer: AudioMixer | nullname: stringplay: (buffer: AudioBufferHandle, config: PlayConfig) => AudioHandle@@ -6378,13 +6385,14 @@ writeCacheFile: ((key: string, bytes: ArrayBuffer) => Promise<void>) | undefined## PlatformAudioBackend — interface @experimental```+delivery: AudioDeliverydispose: () => voidensureResumed: () => Promise<void>getFrequencyData: ((out: Uint8Array) => boolean) | undefinedinitialize: (options?: AudioBackendInitOptions) => Promise<void>isReady: boolean-loadBuffer: (url: string) => Promise<AudioBufferHandle>-loadBufferFromData: (url: string, data: ArrayBuffer) => Promise<AudioBufferHandle>+loadBuffer: (src: string) => Promise<AudioBufferHandle>+loadBufferFromData: (src: string, data: ArrayBuffer) => Promise<AudioBufferHandle>mixer: AudioMixer | nullname: stringplay: (buffer: AudioBufferHandle, config: PlayConfig) => AudioHandlediff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.mdindex 91ec5abc8..39a182e46 100644--- a/sdk/etc/wechat.api.md+++ b/sdk/etc/wechat.api.md@@ -1,7 +1,7 @@# API surface — esengine/wechat<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 114 public · 94 beta · 1692 experimental · 3 deprecated+Symbols: 114 public · 94 beta · 1693 experimental · 3 deprecated## ANCHOR_AXES — const @experimental```@@ -971,6 +971,7 @@ ResourceDef<AudioAPI>```baseUrl: stringbufferBudget: number+delivery: AudioDeliverydispose: () => voidensureBus: (name: string, parent?: string) => booleangetBufferHandle: (url: string) => AudioBufferHandle | undefined@@ -1074,6 +1075,11 @@ parent: string | undefinedvolume: number | undefined```+## AudioDelivery — type @experimental+```+'bytes' | 'url'+```+## AudioHandle — interface @experimental```currentTime: number@@ -2024,14 +2030,14 @@ before: numberdelta: numberkey: stringtier: CensusTier-unit: "count" | "bytes"+unit: "bytes" | "count"```## CensusEntry — interface @experimental```key: stringtier: CensusTier-unit: "count" | "bytes"+unit: "bytes" | "count"value: number```@@ -2076,7 +2082,7 @@ reason: string | undefinedrisingFraction: numberslopePerCycle: numbertier: CensusTier-unit: "count" | "bytes"+unit: "bytes" | "count"```## ChainCollider2D — const @experimental@@ -6139,13 +6145,14 @@ writeCacheFile: ((key: string, bytes: ArrayBuffer) => Promise<void>) | undefined## PlatformAudioBackend — interface @experimental```+delivery: AudioDeliverydispose: () => voidensureResumed: () => Promise<void>getFrequencyData: ((out: Uint8Array) => boolean) | undefinedinitialize: (options?: AudioBackendInitOptions) => Promise<void>isReady: boolean-loadBuffer: (url: string) => Promise<AudioBufferHandle>-loadBufferFromData: (url: string, data: ArrayBuffer) => Promise<AudioBufferHandle>+loadBuffer: (src: string) => Promise<AudioBufferHandle>+loadBufferFromData: (src: string, data: ArrayBuffer) => Promise<AudioBufferHandle>mixer: AudioMixer | nullname: stringplay: (buffer: AudioBufferHandle, config: PlayConfig) => AudioHandlediff --git a/sdk/src/asset/loaders/AudioAssetLoader.ts b/sdk/src/asset/loaders/AudioAssetLoader.tsindex 19493f5f5..fe8ccc812 100644--- a/sdk/src/asset/loaders/AudioAssetLoader.ts+++ b/sdk/src/asset/loaders/AudioAssetLoader.ts@@ -23,9 +23,15 @@ export class AudioAssetLoader implements AssetLoader<AudioResult> {if (audio.retainBuffer(path)) {return { bufferId: path };}- const buildPath = ctx.catalog.getBuildPath(path);- const buffer = await ctx.loadBinary(buildPath);- await audio.preloadFromData(path, buffer);+ // A `url` backend (a mini-game player) streams the file itself: fetching+ // it here reads the whole clip into memory to drop it, and its source+ // comes from the ref resolver rather than from this loader.+ if (audio.delivery === 'url') {+ await audio.preload(path);+ } else {+ const buildPath = ctx.catalog.getBuildPath(path);+ await audio.preloadFromData(path, await ctx.loadBinary(buildPath));+ }audio.retainBuffer(path);return { bufferId: path };}diff --git a/sdk/src/audio/Audio.ts b/sdk/src/audio/Audio.tsindex 6b9280c42..3d9d18ea7 100644--- a/sdk/src/audio/Audio.ts+++ b/sdk/src/audio/Audio.ts@@ -1,6 +1,6 @@// SPDX-License-Identifier: Apache-2.0// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team-import type { PlatformAudioBackend, AudioBufferHandle, AudioHandle, PlayConfig } from './PlatformAudioBackend';+import type { PlatformAudioBackend, AudioBufferHandle, AudioHandle, PlayConfig, AudioDelivery } from './PlatformAudioBackend';import type { AudioMixer, BusDuckRule } from './AudioMixer';import type { BusEffectDef } from './BusEffects';import { defineResource } from '../ecs/resource';@@ -131,6 +131,13 @@ export class AudioAPI {this.mixer_ = mixer;}+ /** What this platform's backend needs in order to play a clip — asked by the+ * asset loader, so a `url` backend is not made to wait on a fetch whose+ * bytes it then drops. See {@link AudioDelivery}. */+ get delivery(): AudioDelivery {+ return this.backend_.delivery;+ }+// =========================================================================// Buffer residency (held → evictable → evicted)// =========================================================================@@ -324,8 +331,14 @@ export class AudioAPI {await Promise.all(urls.map(url => this.preload(url)));}+ /**+ * Cache `url`'s clip from bytes the caller already holds. `url` is the+ * AUTHORED path this API is addressed by (the key `retainBuffer` and+ * `getBufferHandle` take); the backend is handed the RESOLVED source, which+ * for a `url`-delivery backend is the only thing it plays.+ */async preloadFromData(url: string, data: ArrayBuffer): Promise<void> {- await this.ensureBuffer_(url, () => this.backend_.loadBufferFromData(url, data));+ await this.ensureBuffer_(url, () => this.backend_.loadBufferFromData(this.resolveUrl_(url), data));}/**diff --git a/sdk/src/audio/MiniGameAudioBackend.ts b/sdk/src/audio/MiniGameAudioBackend.tsindex 6410eae33..1587f1943 100644--- a/sdk/src/audio/MiniGameAudioBackend.ts+++ b/sdk/src/audio/MiniGameAudioBackend.ts@@ -96,6 +96,8 @@ class MiniGameAudioHandle implements AudioHandle {export class MiniGameAudioBackend implements PlatformAudioBackend {readonly name: string;+ // The host owns the fetch: a player is handed a `src` and streams it.+ readonly delivery = 'url' as const;private readonly g_: MiniGameGlobal;private contexts_ = new Map<number, MiniGameInnerAudioContext>();@@ -123,14 +125,16 @@ export class MiniGameAudioBackend implements PlatformAudioBackend {// Mini-game hosts do not gate playback on a user gesture}- async loadBuffer(url: string): Promise<AudioBufferHandle> {+ async loadBuffer(src: string): Promise<AudioBufferHandle> {const id = ++this.nextId_;- this.urlCache_.set(id, url);+ this.urlCache_.set(id, src);return { id, duration: 0 };}- async loadBufferFromData(url: string, _data: ArrayBuffer): Promise<AudioBufferHandle> {- return this.loadBuffer(url);+ /** No decoder here — the player streams from `src`, and the bytes are dropped.+ * Callers avoid the wasted fetch by reading {@link delivery} first. */+ async loadBufferFromData(src: string, _data: ArrayBuffer): Promise<AudioBufferHandle> {+ return this.loadBuffer(src);}unloadBuffer(handle: AudioBufferHandle): void {diff --git a/sdk/src/audio/NativeAudioBackend.ts b/sdk/src/audio/NativeAudioBackend.tsindex b0491a883..bfc9a796a 100644--- a/sdk/src/audio/NativeAudioBackend.ts+++ b/sdk/src/audio/NativeAudioBackend.ts@@ -61,6 +61,7 @@ class NativeAudioHandle implements AudioHandle {export class NativeAudioBackend implements PlatformAudioBackend {readonly name = 'native';+ readonly delivery = 'bytes' as const;readonly mixer: AudioMixer | null = null;readonly isReady = true;diff --git a/sdk/src/audio/NullAudioBackend.ts b/sdk/src/audio/NullAudioBackend.tsindex 914883cdc..2f7e8e0a1 100644--- a/sdk/src/audio/NullAudioBackend.ts+++ b/sdk/src/audio/NullAudioBackend.ts@@ -28,6 +28,9 @@ class NullAudioHandle implements AudioHandle {}export class NullAudioBackend implements PlatformAudioBackend {+ // Nothing is decoded here, so asking a caller to fetch bytes for it would be+ // pure waste — a clip reaches this backend as a source it never opens.+ readonly delivery = 'url' as const;readonly name = 'null';readonly mixer: AudioMixer | null = null;readonly isReady = true;diff --git a/sdk/src/audio/PlatformAudioBackend.ts b/sdk/src/audio/PlatformAudioBackend.tsindex 15278f712..68899ba66 100644--- a/sdk/src/audio/PlatformAudioBackend.ts+++ b/sdk/src/audio/PlatformAudioBackend.ts@@ -45,14 +45,26 @@ export interface AudioBackendInitOptions {mixerConfig?: AudioMixerConfig;}+/**+ * What a backend needs in order to play a clip: `bytes` decodes a buffer the+ * caller fetched, `url` hands the host a source it fetches itself (a mini-game's+ * InnerAudioContext). A `url` backend given a cache KEY rather than a resolved+ * source plays a file the package does not carry.+ */+export type AudioDelivery = 'bytes' | 'url';+export interface PlatformAudioBackend {readonly name: string;readonly mixer: AudioMixer | null;readonly isReady: boolean;+ /** See {@link AudioDelivery}. */+ readonly delivery: AudioDelivery;initialize(options?: AudioBackendInitOptions): Promise<void>;ensureResumed(): Promise<void>;- loadBuffer(url: string): Promise<AudioBufferHandle>;- loadBufferFromData(url: string, data: ArrayBuffer): Promise<AudioBufferHandle>;+ /** @param src a RESOLVED source the host can fetch — never a cache key. */+ loadBuffer(src: string): Promise<AudioBufferHandle>;+ /** @param src as {@link loadBuffer}; `bytes` backends use `data` and ignore it. */+ loadBufferFromData(src: string, data: ArrayBuffer): Promise<AudioBufferHandle>;unloadBuffer(handle: AudioBufferHandle): void;play(buffer: AudioBufferHandle, config: PlayConfig): AudioHandle;suspend(): void;diff --git a/sdk/src/audio/WebAudioBackend.ts b/sdk/src/audio/WebAudioBackend.tsindex cf8e1c8a1..78b841cfc 100644--- a/sdk/src/audio/WebAudioBackend.ts+++ b/sdk/src/audio/WebAudioBackend.ts@@ -139,6 +139,7 @@ function decodedBytes(buf: AudioBuffer): number {export class WebAudioBackend implements PlatformAudioBackend {readonly name = 'WebAudio';+ readonly delivery = 'bytes' as const;private context_: AudioContext | null = null;private mixer_: AudioMixer | null = null;diff --git a/sdk/src/audio/index.ts b/sdk/src/audio/index.tsindex eac178054..3535f6a94 100644--- a/sdk/src/audio/index.ts+++ b/sdk/src/audio/index.ts@@ -19,4 +19,4 @@ export { AttenuationModel, calculateAttenuation, calculatePanning, spatialDistanexport { WebAudioBackend } from './WebAudioBackend';export { MiniGameAudioBackend } from './MiniGameAudioBackend';export { NativeAudioBackend } from './NativeAudioBackend';-export type { AudioHandle, AudioBufferHandle, PlayConfig, PlatformAudioBackend, AudioBackendInitOptions } from './PlatformAudioBackend';+export type { AudioHandle, AudioBufferHandle, PlayConfig, PlatformAudioBackend, AudioBackendInitOptions, AudioDelivery } from './PlatformAudioBackend';diff --git a/sdk/src/core-content.ts b/sdk/src/core-content.tsindex b395e64fe..b2da722ac 100644--- a/sdk/src/core-content.ts+++ b/sdk/src/core-content.ts@@ -551,6 +551,7 @@ export {type AudioBufferHandle,type PlayConfig,type PlatformAudioBackend,+ type AudioDelivery,type AudioBackendInitOptions,type AudioPluginConfig,type AudioBusConfig,diff --git a/sdk/tests/asset-refcount-release.test.ts b/sdk/tests/asset-refcount-release.test.tsindex 784b415b7..d96718923 100644--- a/sdk/tests/asset-refcount-release.test.ts+++ b/sdk/tests/asset-refcount-release.test.ts@@ -53,7 +53,7 @@ function createAudioBackend(): MockAudioBackend {isPlaying: false, currentTime: 0, duration: 1,};const backend: MockAudioBackend = {- name: 'mock', mixer: null, isReady: true,+ name: 'mock', mixer: null, isReady: true, delivery: 'bytes',decodes: [], unloaded: [],initialize: async () => {},ensureResumed: async () => {},diff --git a/sdk/tests/audio-api.test.ts b/sdk/tests/audio-api.test.tsindex 7f7d326af..f3cbef852 100644--- a/sdk/tests/audio-api.test.ts+++ b/sdk/tests/audio-api.test.ts@@ -37,6 +37,9 @@ function createMockBus(name: string): AudioBus {function createMockBackend(): PlatformAudioBackend {return {name: 'MockBackend',+ delivery: 'bytes',+ mixer: null,+ isReady: true,initialize: vi.fn().mockResolvedValue(undefined),ensureResumed: vi.fn().mockResolvedValue(undefined),loadBuffer: vi.fn().mockResolvedValue({ id: 1, duration: 2.0 }),diff --git a/sdk/tests/audio-residency.test.ts b/sdk/tests/audio-residency.test.tsindex ca5021f92..069553053 100644--- a/sdk/tests/audio-residency.test.ts+++ b/sdk/tests/audio-residency.test.ts@@ -26,6 +26,7 @@ function createMockBackend(bytesPerBuffer = 100): MockBackend {};const backend: MockBackend = {name: 'mock',+ delivery: 'bytes',mixer: null,isReady: true,loads: [],diff --git a/sdk/tests/minigame-audio-cooked-src.test.ts b/sdk/tests/minigame-audio-cooked-src.test.tsnew file mode 100644index 000000000..1d78cf38f--- /dev/null+++ b/sdk/tests/minigame-audio-cooked-src.test.ts@@ -0,0 +1,82 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file minigame-audio-cooked-src.test.ts+ * @brief A cooked build renames `tap.wav` to `assets/<hash>.mp3`, and a+ * mini-game player fetches its source by URL. The path the asset+ * system preloads by is the AUTHORED one, so the URL handed to the+ * player must come from the ref resolver — never the cache key.+ */+import { describe, it, expect, vi } from 'vitest';+import { AudioAPI } from '../src/audio/Audio';+import { MiniGameAudioBackend } from '../src/audio/MiniGameAudioBackend';+import { AudioAssetLoader } from '../src/asset/loaders/AudioAssetLoader';+import type { LoadContext } from '../src/asset/AssetLoader';++function createHost() {+ const created: Array<{ src: string; play: ReturnType<typeof vi.fn> }> = [];+ const g = {+ createInnerAudioContext: () => {+ const ctx = {+ src: '', startTime: 0, autoplay: false, loop: false, obeyMuteSwitch: true,+ volume: 1, playbackRate: 1, duration: 0, currentTime: 0, paused: false,+ play: vi.fn(), pause: vi.fn(), stop: vi.fn(), seek: vi.fn(), destroy: vi.fn(),+ onEnded: vi.fn(), offEnded: vi.fn(), onError: vi.fn(),+ };+ created.push(ctx);+ return ctx;+ },+ };+ return { g, created };+}++const COOKED = 'assets/6a1f2c.mp3';++describe('mini-game audio plays the cooked file', () => {+ it('preloaded-by-bytes clips still play the resolved URL', async () => {+ const { g, created } = createHost();+ const audio = new AudioAPI(new MiniGameAudioBackend(g as never, 'WeChat'));+ audio.setRefResolver((ref) => (ref === 'audio/tap.wav' ? COOKED : ref));++ // What AudioAssetLoader does for an AudioSource's clip field: fetch the+ // staged bytes, then hand the AUTHORED path over as the cache key.+ await audio.preloadFromData('audio/tap.wav', new ArrayBuffer(8));+ audio.playSFX('audio/tap.wav');++ expect(created).toHaveLength(1);+ expect(created[0].src).toBe(COOKED);+ });++ it('preloading by ref plays the resolved URL', async () => {+ const { g, created } = createHost();+ const audio = new AudioAPI(new MiniGameAudioBackend(g as never, 'WeChat'));+ audio.setRefResolver((ref) => (ref === 'audio/tap.wav' ? COOKED : ref));++ await audio.preload('audio/tap.wav');+ audio.playSFX('audio/tap.wav');++ expect(created).toHaveLength(1);+ expect(created[0].src).toBe(COOKED);+ });+});++describe('AudioAssetLoader on a url-delivery backend', () => {+ it('preloads the clip without reading bytes it cannot use', async () => {+ const { g, created } = createHost();+ const audio = new AudioAPI(new MiniGameAudioBackend(g as never, 'WeChat'));+ audio.setRefResolver((ref) => (ref === 'audio/tap.wav' ? COOKED : ref));+ const loadBinary = vi.fn(async () => new ArrayBuffer(8));+ const ctx = {+ getAudio: () => audio,+ catalog: { getBuildPath: (p: string) => (p === 'audio/tap.wav' ? COOKED : p) },+ loadBinary,+ } as unknown as LoadContext;++ const result = await new AudioAssetLoader(() => audio).load('audio/tap.wav', ctx);++ expect(result.bufferId).toBe('audio/tap.wav'); // addressed by the AUTHORED path+ expect(loadBinary).not.toHaveBeenCalled();+ audio.playSFX('audio/tap.wav');+ expect(created[0].src).toBe(COOKED);+ });+});diff --git a/tools/baselines/sdk-test-types.json b/tools/baselines/sdk-test-types.jsonindex 5b9f8d0cb..65c9a32fd 100644--- a/tools/baselines/sdk-test-types.json+++ b/tools/baselines/sdk-test-types.json@@ -42,9 +42,6 @@"tests/assets-invalidate-event.test.ts": {"TS2673|Constructor of class 'Assets' is private and only accessible within the class declaration.": 1},- "tests/audio-api.test.ts": {- "TS2739|Type '{ name: string; initialize: Mock<Procedure>; ensureResumed: Mock<Procedure>; loadBuffer: Mock<Procedure>; loadBufferFromData: Mock<...>; ... 4 more ...; dispose: Mock<...>; }' is missing the following properties from type 'PlatformAudioBackend': mixer, isReady": 1- },"tests/audio-backend-factory.test.ts": {"TS18048|'platform.createAudioBackend' is possibly 'undefined'.": 3,"TS2722|Cannot invoke an object which is possibly 'undefined'.": 3,