# PlayHandle

Kind: Class · Namespace: Sansar.Simulation · Assembly: Sansar.Simulation.dll · Script API 47.10.0

<div class="api-meta">
<span class="api-kind api-kind-class" data-pagefind-filter="kind:Class">Class</span>
<span data-pagefind-filter="namespace:Sansar.Simulation">Namespace <a href="/scripting/api/sansar.simulation"><code>Sansar.Simulation</code></a></span>
<span>Inherits <a href="/scripting/api/sansar.script/instanceinterface">Sansar.Script.InstanceInterface</a>, <a href="https://learn.microsoft.com/dotnet/api/system.idisposable">IDisposable</a></span>
</div>

<span id="T:Sansar.Simulation.PlayHandle"></span>

The PlayHandle represents audio play handles.

```csharp
public class PlayHandle : Sansar.Script.InstanceInterface, IDisposable
```

## Members at a glance

| Kind | Members |
|---|---|
| **Methods** | [Dispose](#dispose) · [Finalize](#finalize) · [GetLoudness](#getloudness) · [GetPitchShift](#getpitchshift) · [GetRemainingSeconds](#getremainingseconds) · [GetStatus](#getstatus) · [IsPlaying](#isplaying) · [OnFinished](#onfinished) · [SetLoudness](#setloudness) · [SetPitchShift](#setpitchshift) · [Stop](#stop) |

## Methods

### Dispose

<div class="api-card">
<span id="M:Sansar.Simulation.PlayHandle.Dispose"></span>
<span id="M:Sansar.Simulation.PlayHandle.Dispose()"></span>

```csharp signature
public void Dispose()
```

Releases resources held by this instance.

</div>

### Finalize

<div class="api-card">
<span id="M:Sansar.Simulation.PlayHandle.Finalize"></span>
<span id="M:Sansar.Simulation.PlayHandle.Finalize()"></span>

```csharp signature
void Finalize()
```



<details class="api-remarks"><summary>Remarks</summary>

Ensures that this instance has been Disposed.

</details>

</div>

### GetLoudness

<div class="api-card">
<span id="M:Sansar.Simulation.PlayHandle.GetLoudness"></span>
<span id="M:Sansar.Simulation.PlayHandle.GetLoudness()"></span>

```csharp signature
public float GetLoudness()
```

Retrieves the loudness for this PlayHandle.

**Returns:** [float](https://learn.microsoft.com/dotnet/api/system.single) — The loudness (in dB).

<details class="api-remarks"><summary>Remarks</summary>

This synchronous method returns the broadcasted loudness.  It does not wait to hear back from clients.

</details>

</div>

### GetPitchShift

<div class="api-card">
<span id="M:Sansar.Simulation.PlayHandle.GetPitchShift"></span>
<span id="M:Sansar.Simulation.PlayHandle.GetPitchShift()"></span>

```csharp signature
public float GetPitchShift()
```

Retrieves the relative pitch for this PlayHandle.

**Returns:** [float](https://learn.microsoft.com/dotnet/api/system.single) — The relative pitch.

<details class="api-remarks"><summary>Remarks</summary>

This synchronous method returns the broadcasted pitch.  It does not wait to hear back from clients.

</details>

</div>

### GetRemainingSeconds

<div class="api-card">
<span id="M:Sansar.Simulation.PlayHandle.GetRemainingSeconds"></span>
<span id="M:Sansar.Simulation.PlayHandle.GetRemainingSeconds()"></span>

```csharp signature
public float GetRemainingSeconds()
```

Returns the number of seconds remaining.

**Returns:** [float](https://learn.microsoft.com/dotnet/api/system.single) — The number of seconds remaining. (0 if done playing, -1 if looped)

</div>

### GetStatus

<div class="api-card">
<span id="M:Sansar.Simulation.PlayHandle.GetStatus"></span>
<span id="M:Sansar.Simulation.PlayHandle.GetStatus()"></span>

```csharp signature
public PlayStatus GetStatus()
```

Returns the current PlayStatus.

**Returns:** [PlayStatus](/scripting/api/sansar.simulation/playstatus) — The current PlayStatus.

</div>

### IsPlaying

<div class="api-card">
<span id="M:Sansar.Simulation.PlayHandle.IsPlaying"></span>
<span id="M:Sansar.Simulation.PlayHandle.IsPlaying()"></span>

```csharp signature
public bool IsPlaying()
```

Returns whether the sound is currently playing.

**Returns:** [bool](https://learn.microsoft.com/dotnet/api/system.boolean) — true if currently playing

</div>

### OnFinished

<div class="api-card">
<span id="M:Sansar.Simulation.PlayHandle.OnFinished(System.Action)"></span>

```csharp signature
public void OnFinished(Action handler)
```

Triggers action when this sound is finished playing.  Doesn&#39;t trigger if stopped or looping.

| Parameter | Type | Description |
|---|---|---|
| `handler` | [Action](https://learn.microsoft.com/dotnet/api/system.action) | Action to be called when the sound finishes playing. |

</div>

### SetLoudness

<div class="api-card" id="setloudness-single">
<span id="M:Sansar.Simulation.PlayHandle.SetLoudness(System.Single)"></span>

```csharp signature
public void SetLoudness(float loudness)
```

Sets the loudness for this PlayHandle.

| Parameter | Type | Description |
|---|---|---|
| `loudness` | [float](https://learn.microsoft.com/dotnet/api/system.single) | The loudness (in dB). |

<details class="api-remarks"><summary>Remarks</summary>

This asynchronous method queues the write then returns. To block until the write has occurred, pass this method to [`ScriptBase.WaitFor`](/scripting/api/sansar.script/scriptbase#waitfor) while in a coroutine.

</details>

</div>

<div class="api-card" id="setloudness-single-operationcomplete">
<span id="M:Sansar.Simulation.PlayHandle.SetLoudness(System.Single,Sansar.Script.ScriptBase.OperationComplete)"></span>
<div class="api-badges"><span class="api-badge api-deprecated">Deprecated</span></div>

```csharp signature
[System.Obsolete("Deprecated. Use the Action<> overload", false)]
public ulong SetLoudness(
    float loudness,
    Sansar.Script.ScriptBase.OperationComplete handler
)
```

Sets the loudness for this PlayHandle.

| Parameter | Type | Description |
|---|---|---|
| `loudness` | [float](https://learn.microsoft.com/dotnet/api/system.single) | The loudness (in dB). |
| `handler` | [Sansar.Script.ScriptBase.OperationComplete](/scripting/api/sansar.script/scriptbase.operationcomplete) | Handler to be called when the event completes. |

**Returns:** [ulong](https://learn.microsoft.com/dotnet/api/system.uint64) — The return value is an internal event id.

<details class="api-remarks"><summary>Remarks</summary>

This asynchronous method queues the write then returns. To block until the write has occurred, pass this method to [`ScriptBase.WaitFor`](/scripting/api/sansar.script/scriptbase#waitfor) while in a coroutine.

</details>

</div>

<div class="api-card" id="setloudness-single-action">
<span id="M:Sansar.Simulation.PlayHandle.SetLoudness(System.Single,System.Action{Sansar.Script.OperationCompleteEvent})"></span>

```csharp signature
public void SetLoudness(
    float loudness,
    Action<Sansar.Script.OperationCompleteEvent> handler
)
```

Sets the loudness for this PlayHandle.

| Parameter | Type | Description |
|---|---|---|
| `loudness` | [float](https://learn.microsoft.com/dotnet/api/system.single) | The loudness (in dB). |
| `handler` | [Action&lt;Sansar.Script.OperationCompleteEvent&gt;](https://learn.microsoft.com/dotnet/api/system.action-1) | Handler to be called when the event completes. |

<details class="api-remarks"><summary>Remarks</summary>

This asynchronous method queues the write then returns. To block until the write has occurred, pass this method to [`ScriptBase.WaitFor`](/scripting/api/sansar.script/scriptbase#waitfor) while in a coroutine.

</details>

</div>

### SetPitchShift

<div class="api-card" id="setpitchshift-single">
<span id="M:Sansar.Simulation.PlayHandle.SetPitchShift(System.Single)"></span>

```csharp signature
public void SetPitchShift(float pitch)
```

Sets the relative pitch for this PlayHandle.

| Parameter | Type | Description |
|---|---|---|
| `pitch` | [float](https://learn.microsoft.com/dotnet/api/system.single) | The relative pitch in semitones.  (default = 0) |

<details class="api-remarks"><summary>Remarks</summary>

This asynchronous method queues the write then returns. To block until the write has occurred, pass this method to [`ScriptBase.WaitFor`](/scripting/api/sansar.script/scriptbase#waitfor) while in a coroutine.

</details>

</div>

<div class="api-card" id="setpitchshift-single-operationcomplete">
<span id="M:Sansar.Simulation.PlayHandle.SetPitchShift(System.Single,Sansar.Script.ScriptBase.OperationComplete)"></span>
<div class="api-badges"><span class="api-badge api-deprecated">Deprecated</span></div>

```csharp signature
[System.Obsolete("Deprecated. Use the Action<> overload", false)]
public ulong SetPitchShift(
    float pitch,
    Sansar.Script.ScriptBase.OperationComplete handler
)
```

Sets the relative pitch for this PlayHandle.

| Parameter | Type | Description |
|---|---|---|
| `pitch` | [float](https://learn.microsoft.com/dotnet/api/system.single) | The relative pitch in semitones.  (default = 0) |
| `handler` | [Sansar.Script.ScriptBase.OperationComplete](/scripting/api/sansar.script/scriptbase.operationcomplete) | Handler to be called when the event completes. |

**Returns:** [ulong](https://learn.microsoft.com/dotnet/api/system.uint64) — The return value is an internal event id.

<details class="api-remarks"><summary>Remarks</summary>

This asynchronous method queues the write then returns. To block until the write has occurred, pass this method to [`ScriptBase.WaitFor`](/scripting/api/sansar.script/scriptbase#waitfor) while in a coroutine.

</details>

</div>

<div class="api-card" id="setpitchshift-single-action">
<span id="M:Sansar.Simulation.PlayHandle.SetPitchShift(System.Single,System.Action{Sansar.Script.OperationCompleteEvent})"></span>

```csharp signature
public void SetPitchShift(
    float pitch,
    Action<Sansar.Script.OperationCompleteEvent> handler
)
```

Sets the relative pitch for this PlayHandle.

| Parameter | Type | Description |
|---|---|---|
| `pitch` | [float](https://learn.microsoft.com/dotnet/api/system.single) | The relative pitch in semitones.  (default = 0) |
| `handler` | [Action&lt;Sansar.Script.OperationCompleteEvent&gt;](https://learn.microsoft.com/dotnet/api/system.action-1) | Handler to be called when the event completes. |

<details class="api-remarks"><summary>Remarks</summary>

This asynchronous method queues the write then returns. To block until the write has occurred, pass this method to [`ScriptBase.WaitFor`](/scripting/api/sansar.script/scriptbase#waitfor) while in a coroutine.

</details>

</div>

### Stop

<div class="api-card" id="stop-noargs">
<span id="M:Sansar.Simulation.PlayHandle.Stop"></span>
<span id="M:Sansar.Simulation.PlayHandle.Stop()"></span>

```csharp signature
public void Stop()
```

Stops the sound on this PlayHandle.

<details class="api-remarks"><summary>Remarks</summary>

This asynchronous method queues the write then returns.

</details>

</div>

<div class="api-card" id="stop-operationcomplete">
<span id="M:Sansar.Simulation.PlayHandle.Stop(Sansar.Script.ScriptBase.OperationComplete)"></span>
<div class="api-badges"><span class="api-badge api-deprecated">Deprecated</span></div>

```csharp signature
[System.Obsolete("Deprecated. Use the Action<> overload", false)]
public ulong Stop(Sansar.Script.ScriptBase.OperationComplete handler)
```

Stops the sound on this PlayHandle.

| Parameter | Type | Description |
|---|---|---|
| `handler` | [Sansar.Script.ScriptBase.OperationComplete](/scripting/api/sansar.script/scriptbase.operationcomplete) | Handler to be called when the event completes. |

**Returns:** [ulong](https://learn.microsoft.com/dotnet/api/system.uint64) — The return value is an internal event id.

<details class="api-remarks"><summary>Remarks</summary>

This asynchronous method queues the write then returns.

</details>

</div>

<div class="api-card" id="stop-action">
<span id="M:Sansar.Simulation.PlayHandle.Stop(System.Action{Sansar.Script.OperationCompleteEvent})"></span>

```csharp signature
public void Stop(Action<Sansar.Script.OperationCompleteEvent> handler)
```

Stops the sound on this PlayHandle.

| Parameter | Type | Description |
|---|---|---|
| `handler` | [Action&lt;Sansar.Script.OperationCompleteEvent&gt;](https://learn.microsoft.com/dotnet/api/system.action-1) | Handler to be called when the event completes. |

<details class="api-remarks"><summary>Remarks</summary>

This asynchronous method queues the write then returns.

</details>

</div>

<div class="api-card" id="stop-boolean">
<span id="M:Sansar.Simulation.PlayHandle.Stop(System.Boolean)"></span>

```csharp signature
public void Stop(bool fadeout)
```

Stops the sound on this PlayHandle.

| Parameter | Type | Description |
|---|---|---|
| `fadeout` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Will fade out if true. |

<details class="api-remarks"><summary>Remarks</summary>

This asynchronous method queues the write then returns.

</details>

</div>

<div class="api-card" id="stop-boolean-operationcomplete">
<span id="M:Sansar.Simulation.PlayHandle.Stop(System.Boolean,Sansar.Script.ScriptBase.OperationComplete)"></span>
<div class="api-badges"><span class="api-badge api-deprecated">Deprecated</span></div>

```csharp signature
[System.Obsolete("Deprecated. Use the Action<> overload", false)]
public ulong Stop(
    bool fadeout,
    Sansar.Script.ScriptBase.OperationComplete handler
)
```

Stops the sound on this PlayHandle.

| Parameter | Type | Description |
|---|---|---|
| `fadeout` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Will fade out if true. |
| `handler` | [Sansar.Script.ScriptBase.OperationComplete](/scripting/api/sansar.script/scriptbase.operationcomplete) | Handler to be called when the event completes. |

**Returns:** [ulong](https://learn.microsoft.com/dotnet/api/system.uint64) — The return value is an internal event id.

<details class="api-remarks"><summary>Remarks</summary>

This asynchronous method queues the write then returns.

</details>

</div>

<div class="api-card" id="stop-boolean-action">
<span id="M:Sansar.Simulation.PlayHandle.Stop(System.Boolean,System.Action{Sansar.Script.OperationCompleteEvent})"></span>

```csharp signature
public void Stop(
    bool fadeout,
    Action<Sansar.Script.OperationCompleteEvent> handler
)
```

Stops the sound on this PlayHandle.

| Parameter | Type | Description |
|---|---|---|
| `fadeout` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Will fade out if true. |
| `handler` | [Action&lt;Sansar.Script.OperationCompleteEvent&gt;](https://learn.microsoft.com/dotnet/api/system.action-1) | Handler to be called when the event completes. |

<details class="api-remarks"><summary>Remarks</summary>

This asynchronous method queues the write then returns.

</details>

</div>


## Used in examples

- [EventExample.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/EventExample.cs)
- [ScriptLibrary/Scene/AudioStream.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/ScriptLibrary/Scene/AudioStream.cs)
- [ScriptLibrary/Scene/Sound.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/ScriptLibrary/Scene/Sound.cs)

<p class="api-generated" data-pagefind-ignore>Generated from the Sansar 47.10.0 client ScriptApi snapshot.</p>