← Typed assets

Assets.audio

luastra/assets
Assets.audio(id: string): Audio

Creates a typed reference to an admitted audio asset while retaining the asset kind and canonical asset URI. The reference can be stored safely before a media queue is assembled.

Before you use it

Add luastra/assets to this module's dependencies in luastra.json, then import it with require("luastra/assets"). Declare the referenced file in luastra.json with its stable asset id and admitted media type. Image assets are PNG, JPEG, WebP, or AVIF; audio assets and WOFF2 fonts use their own declared types.

How it fits

The constructor validates an asset id and returns a typed reference synchronously. It does not read a file. Assets.uri exposes the packaged asset URI for a consuming UI or Media API.

When to use it

Use Assets.audio when building Media.QueueItem values for sounds shipped with the application. Use a trusted HTTPS source only where the media contract explicitly admits one; do not disguise a filesystem path as an asset ID.

Parameters

ParameterType / valuesDescription
idstringManifest asset ID whose declared media type is admitted audio.

Returns

Audio — a typed audio reference admitted from the project manifest.

What happens next

A checked reference or canonical asset URI that a compatible API can consume.

Failures and fixes

A malformed id, missing manifest entry, wrong media kind, unsupported media type, or missing source file fails during project checking or packaging. Assets.font can be applied through UI.TextStyle in the 0.3 source SDK. A missing or wrong-kind font fails when the rendered tree resolves its asset; a failed browser font decode/load retains the selected fallback.

Availability

Public-source alpha API in 0.5.0-alpha; supported consumers vary by asset kind.

Focused example

local Assets = require("luastra/assets")
local intro = Assets.audio("audio/intro")

Complete inventory

View all pages in Typed assets
← Previous: Assets.imageNext: Assets.font →