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(native): video plays on the device — cook it, then decode it
esengine6bc39017ec49
diff --git a/desktop/electron/exportGame.ts b/desktop/electron/exportGame.tsindex aa4334741..5d007a543 100644--- a/desktop/electron/exportGame.ts+++ b/desktop/electron/exportGame.ts@@ -517,7 +517,13 @@ export async function exportGame(opts: {// 1. Cook reachable assets + manifest, from EVERY shippable scene as a root// (the scene files themselves are staged too).progress({ phase: 'Cooking assets' });- const cook = await cookAssets(opts.root, { entryScenes: scenes.map((s) => s.path), outDir: payloadDir, contentAddressed: opts.contentAddressed ?? true, compressTextures: opts.compressTextures, compressAudio: opts.compressAudio, atlasTextures: opts.atlasTextures, platform });+ // Video ships as MPEG-1 `.esv` for every target whose only decoder is the+ // pl_mpeg path — a device (native) and WeChat both play video through it, so+ // both need the cook. Browser/Chromium targets (web, desktop) decode the source+ // container directly and keep it. Without this a device shows a blank frame: it+ // cannot decode an .mp4.+ const transcodeVideo = isNativePlatform(platform) || platform === 'wechat';+ const cook = await cookAssets(opts.root, { entryScenes: scenes.map((s) => s.path), outDir: payloadDir, contentAddressed: opts.contentAddressed ?? true, compressTextures: opts.compressTextures, compressAudio: opts.compressAudio, atlasTextures: opts.atlasTextures, transcodeVideo, platform });warnings.push(...cook.warnings);warnings.push(...await unsupportedContentWarnings(opts.root, cook.includedPaths, platform));progress({ phase: 'Cooking assets', detail: `${cook.included.length} reachable` });diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.mdindex 5e654a18c..364eb7c9c 100644--- a/sdk/etc/index.native.api.md+++ b/sdk/etc/index.native.api.md@@ -4173,6 +4173,7 @@ clearStorage: (prefix: string) => voidcreateAudioBackend: (() => PlatformAudioBackend) | undefinedcreateCanvas: (_width: number, _height: number) => PlatformCanvascreateImage: () => PlatformImage+createVideoBackend: (ctx: VideoBackendContext) => PlatformVideoBackenddevicePixelRatio: () => numberfetch: (url: string, options?: PlatformRequestOptions) => Promise<PlatformResponse>fileExists: (path: string) => Promise<boolean>diff --git a/sdk/src/platform/native/adapter.ts b/sdk/src/platform/native/adapter.tsindex 33884d9a6..6d6bbb04b 100644--- a/sdk/src/platform/native/adapter.ts+++ b/sdk/src/platform/native/adapter.ts@@ -27,6 +27,8 @@ import type {PlatformGlyphRequest,} from '../types';import type { PlatformAudioBackend } from '../../audio/PlatformAudioBackend';+import type { PlatformVideoBackend, VideoBackendContext } from '../../video/PlatformVideoBackend';+import { WasmVideoBackend } from '../../video/WasmVideoBackend';import { setPlatform } from '../base';import { createPrimaryPointer } from '../primaryPointer';import { NativeAudioBackend } from '../../audio/NativeAudioBackend';@@ -193,8 +195,16 @@ export class NativePlatformAdapter implements PlatformAdapter {if (this.bridge_.writeCacheFile) await this.bridge_.writeCacheFile(key, bytes);}- // createSocket / createVideoBackend / pollGamepads / loadSubpackage are- // optional and deferred to the shell.+ // The engine-owned software decoder, exactly as the mini-game family uses it:+ // the videodec runtime is compiled into the device binary (a side module the+ // host answers through es_video_*), so WasmVideoBackend acquires it off+ // app.sideModules and plays a cooked `.esv` — a device has no other video path.+ createVideoBackend(ctx: VideoBackendContext): PlatformVideoBackend {+ return new WasmVideoBackend(ctx);+ }++ // createSocket / pollGamepads / loadSubpackage are optional and deferred to+ // the shell.}/** Install a {@link NativePlatformAdapter} built from the host `bridge` as the