> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nanoforge.eu/llms.txt
> Use this file to discover all available pages before exploring further.

# MusicLibrary

> Built-in music library.

Defined in: [modules/music/src/music.library.ts:14](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/music/src/music.library.ts#L14)

Built-in music library.

## Remarks

Manages a collection of named `HTMLAudioElement` instances and ensures
only one track plays at a time — unlike `SoundLibrary`, starting a new
track pauses whichever one was playing.

## Extends

* `Library`

## Implements

* [`EditorAwareLibrary`](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/interfaces/EditorAwareLibrary)

## Constructors

### Constructor

> **new MusicLibrary**(`relationships?`): `MusicLibrary`

Defined in: packages/common/dist/index.d.ts:510

#### Parameters

##### relationships?

`Partial`\<`LibraryRelationships`>

Optional ordering overrides, keyed by other
libraries' `key`.

#### Returns

`MusicLibrary`

#### Inherited from

`Library.constructor`

## Properties

### key

> `readonly` **key**: `"music"`

Defined in: [modules/music/src/music.library.ts:15](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/music/src/music.library.ts#L15)

This library's identity: its slot on `Context`, its registry key, and
the identifier used to reference it in ordering relationships.

#### Overrides

`Library.key`

## Accessors

### relationships

#### Get Signature

> **get** **relationships**(): `LibraryRelationships`

Defined in: packages/common/dist/index.d.ts:512

**`Internal`**

##### Returns

`LibraryRelationships`

#### Inherited from

`Library.relationships`

## Methods

### \_\_clear()

> **\_\_clear**(): `Promise`\<`void`>

Defined in: [modules/music/src/music.library.ts:37](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/music/src/music.library.ts#L37)

Called once after the tick loop stops.

#### Returns

`Promise`\<`void`>

#### Overrides

`Library.__clear`

***

### \_\_editorInit()

> **\_\_editorInit**(`ctx`): `Promise`\<`void`>

Defined in: [modules/music/src/music.library.ts:30](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/music/src/music.library.ts#L30)

Listens to the editor's `mute` command.

#### Parameters

##### ctx

[`EditorInitContext`](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/type-aliases/EditorInitContext)

#### Returns

`Promise`\<`void`>

#### Implementation of

[`EditorAwareLibrary`](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/interfaces/EditorAwareLibrary).[`__editorInit`](https://docs.nanoforge.eu/references/engine/3.0.0/editor-lib/interfaces/EditorAwareLibrary#__editorinit)

***

### \_\_events()

> **\_\_events**(`_ctx`): `Promise`\<`void`>

Defined in: packages/common/dist/index.d.ts:521

Called every tick, in run order, whether or not the tick loop is
paused — unlike `__run`. Use this for event/message draining that must
not be affected by pause (e.g. listening for the command that resumes
the loop), not for gameplay simulation.

#### Parameters

##### \_ctx

[`Context`](https://docs.nanoforge.eu/references/engine/3.0.0/ecs/index/interfaces/Context)

#### Returns

`Promise`\<`void`>

#### Inherited from

`Library.__events`

***

### \_\_init()

> **\_\_init**(): `Promise`\<`void`>

Defined in: [modules/music/src/music.library.ts:23](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/music/src/music.library.ts#L23)

Called once, in dependency order, before the tick loop starts.

#### Returns

`Promise`\<`void`>

#### Overrides

`Library.__init`

***

### \_\_run()

> **\_\_run**(`_ctx`): `Promise`\<`void`>

Defined in: packages/common/dist/index.d.ts:523

Called every tick, in run order, while the tick loop is active and not paused.

#### Parameters

##### \_ctx

[`Context`](https://docs.nanoforge.eu/references/engine/3.0.0/ecs/index/interfaces/Context)

#### Returns

`Promise`\<`void`>

#### Inherited from

`Library.__run`

***

### expose()

> **expose**(): [`MusicContextApi`](https://docs.nanoforge.eu/references/engine/3.0.0/music/interfaces/MusicContextApi)

Defined in: [modules/music/src/music.library.ts:83](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/music/src/music.library.ts#L83)

Returns this library's public contribution to `Context[this.key]`.

#### Returns

[`MusicContextApi`](https://docs.nanoforge.eu/references/engine/3.0.0/music/interfaces/MusicContextApi)

#### Remarks

Return a plain object exposing only what game code should be able to
reach — never `this` — so internal state and lifecycle hooks never leak
onto `Context`. Libraries with nothing to expose (headless libraries)
can leave this unimplemented; they simply won't appear on `Context`.

#### Overrides

`Library.expose`

***

### load()

> **load**(`key`, `file`): `void`

Defined in: [modules/music/src/music.library.ts:51](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/music/src/music.library.ts#L51)

Registers a music track under a unique key.

#### Parameters

##### key

`string`

##### file

`string`

#### Returns

`void`

#### Remarks

Creates an `HTMLAudioElement` from the given URL. The track respects
the current muted state at load time.

***

### mute()

> **mute**(): `void`

Defined in: [modules/music/src/music.library.ts:77](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/music/src/music.library.ts#L77)

Toggles the muted state of every loaded track.

#### Returns

`void`

***

### play()

> **play**(`key`): `void`

Defined in: [modules/music/src/music.library.ts:61](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/music/src/music.library.ts#L61)

#### Parameters

##### key

`string`

#### Returns

`void`

#### Throws

`NfNotFound` When no track is registered under the given key.

***

### throwNotInitializedError()

> `protected` **throwNotInitializedError**(): `never`

Defined in: packages/common/dist/index.d.ts:536

#### Returns

`never`

#### Inherited from

`Library.throwNotInitializedError`


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.