> ## 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.

# Player

> Handle to a device that outputs sounds.

Dropping the `Player` (prevent this by holding a reference) stops
all its sounds.

## Constructor

```typescript
Player(): Player
```

### Returns

`Player`

## Properties

<ResponseField name={"isPaused"} type={"boolean"} required>
  Whether the player is currently paused. Players can be paused
  and resumed using `pause()` and `play()`.
</ResponseField>

<ResponseField name={"speed"} type={"number"} required>
  Playback speed of the sound.

  Increasing the speed will increase the pitch by the same factor.
  For example, speed `0.5` halves the frequency (lowering pitch)
  and speed `2` doubles it (raising pitch). Changes in speed
  affect the total duration inversely.
</ResponseField>

<ResponseField name={"volume"} type={"number"} required>
  Volume of the sound.

  The value `1.0` is the "normal" volume (unfiltered input). Any
  value other than `1.0` will multiply each sample by this value.
</ResponseField>

## Methods

### appendFile()

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

Decodes an audio file and appends it to the playback queue.

Supports WAV, MP3, FLAC, Vorbis/OGG, and other formats
depending on build features.

#### Parameters

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

### appendSamples()

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

Appends a sound to the queue of sounds to play.

#### Parameters

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

### clear()

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

Removes all currently loaded sources from the player and pauses
it.

### empty()

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

Returns `true` if this player has no more sounds to play.

#### Returns

`boolean`

### getPos()

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

Returns the position of the sound that's being played, in
milliseconds.

This takes into account any speedup or delay applied.

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
```

Returns the number of sounds currently in the queue.

#### Returns

`number`

### pause()

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

Pauses playback of this player.

No effect if already paused. A paused player can be resumed 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 source in the player.

If there are more sources appended to the player at the time,
it will play the next one. Otherwise, the player will finish as
if it had finished playing a source all the way through.

### sleepUntilEnd()

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

Sleeps the current thread until the sound ends.

### stop()

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

Stops the player by emptying the queue.

### trySeek()

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

Attempts to seek to the given position (in milliseconds) in the
current source.

This blocks between 0 and \~5 milliseconds.

As long as the duration of the source is known, seek is
guaranteed to saturate at the end of the source. For example
given a source that reports a total duration of 42 seconds,
calling `trySeek(60000)` will seek to 42 seconds.

#### Parameters

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