# Client

### Play

{% code fullWidth="false" %}

```lua
local soundId = exports['mx-surround']:Play(soundId, url, coords, loop, volume, panner)
```

{% endcode %}

{% hint style="info" %}
This export is a synchronous function, which means that this code returns a soundId to you. And if sound is not created, it returns false
{% endhint %}

{% hint style="danger" %}
With 1.8.5 players who are far away from the song will not be able to get the `maxDuration` and `timeStamp`of the song! If you want the far away player to get the maxDuration, you must use server side export
{% endhint %}

#### Parameters

* > **soundId?**: `string`
  >
  > * If not provided, will be created automatically
* > **url**: `string`
* > **coords?**: `vector3`
  >
  > * If not provided, its means that the sound is not dynamic. So player can hear it from everywhere
* > **loop?:** `boolean`
* > **volume?:** `number`
  >
  > * Override default volume (even if sound profile is enabled) (0.0 | 1.0)
* > **panner?:** `PannerNode`
  >
  > * [See how to use](https://developer.mozilla.org/en-US/docs/Web/API/PannerNode?retiredLocale=tr)

#### Returns

* > **`soundId | false`**

***

### Play Async

```lua
exports['mx-surround']:PlayAsync(soundId, url, coords, loop, volume, panner)
```

{% hint style="info" %}
This is the same as a normal play export. The only difference is that it is async. So there is no return value
{% endhint %}

***

### Attach To Entity

```lua
exports['mx-surround']:attachEntity(soundId, networkId)
```

#### Parameters

* > **soundId:** `string`
* > **networkId:** `number`

***

### Detach From Entity

```lua
exports['mx-surround']:detachEntity(soundId)
```

#### Parameters

* > **soundId:** `string`

***

### Attach To Player

{% hint style="info" %}
If you are going to attach to a player, you can of course use the `attachEntity`. **But you should definitely use this**. Because if the player gets in the car, the script detects it with this export and filters the sound.
{% endhint %}

```lua
exports['mx-surround']:attachPlayer(soundId, playerId)
```

#### Parameters

* > **soundId:** `string`
* > **playerId:** `number`

***

### Detach From Player

```lua
exports['mx-surround']:detachPlayer(soundId)
```

#### Parameters

* > **soundId:** `string`

***

### Stop

{% hint style="info" %}
The difference from Pause export is this: If you are playing a song on spotify or youtube, it completely deletes the player so that there is no player in the dom. This is very important for optimization
{% endhint %}

```lua
exports['mx-surround']:Stop(soundId)
```

#### Parameters

* > **soundId:** `string`

***

### Pause

```lua
exports['mx-surround']:Pause(soundId)
```

#### Parameters

* > **soundId:** `string`

***

### Resume

```lua
exports['mx-surround']:Resume(soundId)
```

#### Parameters

* > **soundId:** `string`

***

### Destroy

```lua
exports['mx-surround']:Destroy(soundId)
```

#### Parameters

* > **soundId:** `string`

***

### Destroy All

```lua
exports['mx-surround']:destroyAllSounds()
```

***

### Repeat

```lua
exports['mx-surround']:repeatSound(soundId)
```

#### Parameters

* > **soundId:** `string`

***

### Add Filter

```lua
exports['mx-surround']:addFilter(soundId, type, filter)
```

#### Parameters

* > **soundId:** `string`
* > **type:** `string`
* > **filter**: `{frequency: number, Q: number, gain:number}`

***

### Remove Filter

```lua
exports['mx-surround']:removeFilter(soundId)
```

#### Parameters

* > **soundId:** `string`

***

## To better manage sounds, see these three section

{% content-ref url="client/set" %}
[set](https://docs.moxha.dev/documentation/paid-scripts/surround-spatial-audio/api/client/set)
{% endcontent-ref %}

{% content-ref url="client/get" %}
[get](https://docs.moxha.dev/documentation/paid-scripts/surround-spatial-audio/api/client/get)
{% endcontent-ref %}

{% content-ref url="client/handlers" %}
[handlers](https://docs.moxha.dev/documentation/paid-scripts/surround-spatial-audio/api/client/handlers)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.moxha.dev/documentation/paid-scripts/surround-spatial-audio/api/client.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
