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

# AudioPlayer

> A queue of sounds playing through a []'s default audio output.

A queue of sounds playing through a \[`Machine`]'s default audio
output.

Obtain via \[`Machine.player`]. The handle owns its output device
connection: when it is garbage-collected playback stops. Appended
sources play back to back; playback starts immediately on append.

## Constructor

```typescript
AudioPlayer(): AudioPlayer
```

### Returns

`AudioPlayer`

## Properties

<ResponseField name={"isPaused"} type={"boolean"} required>
  Whether the player is currently paused.
</ResponseField>

<ResponseField name={"speed"} type={"number"} required>
  Playback speed; changing it changes pitch by the same factor.
</ResponseField>

<ResponseField name={"volume"} type={"number"} required>
  Volume multiplier; `1.0` is the unfiltered input.
</ResponseField>

## Methods

### appendFile()

```typescript
appendFile(path: string): void
```

Decodes an audio file (WAV, MP3, FLAC, Vorbis/OGG, ...) on the
**host** and appends it to the playback queue.

#### Parameters

<ResponseField name={"path"} type={"string"} required />

### appendSamples()

```typescript
appendSamples(buffer: SamplesBuffer): void
```

Appends a sound to the end of the playback queue.

#### Parameters

<ResponseField name={"buffer"} type={"SamplesBuffer"} required />

### clear()

```typescript
clear(): void
```

Removes all queued sounds and pauses the player.

### empty()

```typescript
empty(): boolean
```

Whether the queue has no more sounds to play.

#### Returns

`boolean`

### getPos()

```typescript
getPos(): number
```

Playback position within the current sound in milliseconds,
accounting for speed changes and seeks.

Example: if you apply a speedup of *2* to a source and
`getPos()` returns *5000* then the position in the recording
is *10 seconds* from its start.

#### Returns

`number`

### len()

```typescript
len(): number
```

The number of sounds currently in the queue.

#### Returns

`number`

### pause()

```typescript
pause(): void
```

Pauses playback; resume with `play()`.

### play()

```typescript
play(): void
```

Resumes playback of a paused player. No effect if not paused.

### skipOne()

```typescript
skipOne(): void
```

Skips to the next sound in the queue.

### sleepUntilEnd()

```typescript
sleepUntilEnd(): void
```

Blocks the current thread until every queued sound has finished.

### stop()

```typescript
stop(): void
```

Stops the player by emptying the queue.

### trySeek()

```typescript
trySeek(posMs: number): void
```

Seeks within the current sound to the given position (in
milliseconds), saturating at its end when the duration is known.
For example given a source that reports a total duration of 42
seconds, calling `trySeek(60000)` will seek to 42 seconds.

This blocks between 0 and \~5 milliseconds.

#### Parameters

<ResponseField name={"posMs"} type={"number"} required />
