Skip to content

AudioStreamPlayer

Eduard Gushchin edited this page Jun 21, 2026 · 4 revisions

Home | API by Category | Complete API Index | API Compatibility

Field Value
Full name Electron2D.AudioStreamPlayer
Namespace Electron2D
Kind class
Category Audio

Overview

Plays an Electron2D.AudioStream without positional attenuation.

Syntax

public class Electron2D.AudioStreamPlayer : Electron2D.Node

Remarks

Electron2D.AudioStreamPlayer is a scene node for user-interface sounds, menu sounds, music and other playback that should not change with 2D position.

The node owns playback state and asks Electron2D.AudioServer to create internal voices. Internal voice handles are not part of the public API.

Thread Safety

This type is not synchronized. Create and mutate it on the main scene thread that owns the node.

Since

This class is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.AudioServer
  • Electron2D.AudioStream
  • Electron2D.AudioStreamPlayer2D

Members

Member Kind Summary
Autoplay Property Gets or sets whether this node starts playback when it enters a scene tree.
Bus Property Gets or sets the target audio bus name.
MaxPolyphony Property Gets or sets the maximum number of simultaneous voices owned by this node.
PitchScale Property Gets or sets the playback pitch scale.
Playing Property Gets or sets whether this player is currently requested to play.
Stream Property Gets or sets the stream resource played by this node.
StreamPaused Property Gets or sets whether playback is paused.
VolumeDb Property Gets or sets the playback volume in decibels.
VolumeLinear Property Gets or sets the playback volume as linear gain.
Electron2D.AudioStreamPlayer() Constructor Initializes a new instance of the Electron2D.AudioStreamPlayer class.
GetPlaybackPosition() Method Gets the stored playback position.
HasStreamPlayback() Method Checks whether this player currently owns an active stream voice.
Play(System.Single) Method Starts playback from a position in the stream.
Seek(System.Single) Method Changes the stored playback position.
Stop() Method Stops all voices owned by this player.

Member Details

Autoplay

Kind: Property

public System.Boolean Autoplay { get; set; }

Summary

Gets or sets whether this node starts playback when it enters a scene tree.

Remarks

Autoplay only starts when Electron2D.AudioStreamPlayer.Stream is assigned. Removing the node from the tree stops voices owned by this player.

Value

true to call Electron2D.AudioStreamPlayer.Play(System.Single) on enter-tree; otherwise false.

Thread Safety

This property is not synchronized. Access it from the main scene thread.

Since

This property is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.AudioStreamPlayer.Play(System.Single)

Bus

Kind: Property

public Electron2D.StringName Bus { get; set; }

Summary

Gets or sets the target audio bus name.

Remarks

Electron2D.AudioServer resolves this name when playback starts. If the name does not match an existing bus, the voice falls back to Master.

Assigning an empty Electron2D.StringName restores Master.

Value

The requested bus name. The default value is Master.

Thread Safety

This property is not synchronized. Access it from the main scene thread.

Since

This property is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.AudioServer.GetBusName(System.Int32)
  • Electron2D.AudioServer.SetBusName(System.Int32,System.String)
  • Electron2D.AudioServer.SetBusSend(System.Int32,Electron2D.StringName)

MaxPolyphony

Kind: Property

public System.Int32 MaxPolyphony { get; set; }

Summary

Gets or sets the maximum number of simultaneous voices owned by this node.

Remarks

When the limit is reached, the next Electron2D.AudioStreamPlayer.Play(System.Single) call stops the oldest voice owned by this player before starting a new one.

Value

The maximum polyphony count. The default value is 1.

Exceptions

  • System.ArgumentOutOfRangeException: Thrown when the value is less than 1.

Thread Safety

This property is not synchronized. Access it from the main scene thread.

Since

This property is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.AudioStreamPlayer.Play(System.Single)

PitchScale

Kind: Property

public System.Single PitchScale { get; set; }

Summary

Gets or sets the playback pitch scale.

Remarks

A value of 1 plays the stream at its original pitch. A value of 2 doubles pitch and tempo; 0.5 halves them.

Value

A positive finite multiplier applied to stream pitch and tempo.

Exceptions

  • System.ArgumentException: Thrown when the value is not finite.
  • System.ArgumentOutOfRangeException: Thrown when the value is less than or equal to 0.

Thread Safety

This property is not synchronized. Access it from the main scene thread.

Since

This property is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.AudioStreamPlayer.VolumeDb

Playing

Kind: Property

public System.Boolean Playing { get; set; }

Summary

Gets or sets whether this player is currently requested to play.

Remarks

Setting this property to true calls Electron2D.AudioStreamPlayer.Play(System.Single). Setting it to false calls Electron2D.AudioStreamPlayer.Stop.

Value

true when playback is active or paused; otherwise false.

Thread Safety

This property is not synchronized. Access it from the main scene thread.

Since

This property is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.AudioStreamPlayer.StreamPaused

Stream

Kind: Property

public Electron2D.AudioStream Stream { get; set; }

Summary

Gets or sets the stream resource played by this node.

Remarks

Setting this property stops all voices currently owned by this player. Calling Electron2D.AudioStreamPlayer.Play(System.Single) while this property is null does not create a voice.

Value

The stream resource to play, or null when no stream is assigned.

Thread Safety

This property is not synchronized. Access it from the main scene thread.

Since

This property is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.AudioStreamPlayer.Play(System.Single)
  • Electron2D.AudioStreamPlayer.Stop

StreamPaused

Kind: Property

public System.Boolean StreamPaused { get; set; }

Summary

Gets or sets whether playback is paused.

Remarks

Pausing stops active voices but keeps Electron2D.AudioStreamPlayer.Playing true. Clearing this property resumes from the stored playback position when a stream is assigned.

Value

true when playback should pause and resume later; otherwise false.

Thread Safety

This property is not synchronized. Access it from the main scene thread.

Since

This property is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.AudioStreamPlayer.GetPlaybackPosition
  • Electron2D.AudioStreamPlayer.Playing

VolumeDb

Kind: Property

public System.Single VolumeDb { get; set; }

Summary

Gets or sets the playback volume in decibels.

Remarks

Use Electron2D.AudioStreamPlayer.VolumeLinear when the caller works with slider-style linear gain values instead of decibels.

Value

A finite decibel offset applied to the stream.

Exceptions

  • System.ArgumentException: Thrown when the value is not finite.

Thread Safety

This property is not synchronized. Access it from the main scene thread.

Since

This property is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.AudioStreamPlayer.VolumeLinear

VolumeLinear

Kind: Property

public System.Single VolumeLinear { get; set; }

Summary

Gets or sets the playback volume as linear gain.

Remarks

Setting this property updates Electron2D.AudioStreamPlayer.VolumeDb. A value of 0 maps to a quiet floor used by the preview runtime.

Value

A finite non-negative linear gain. The default value is 1.

Exceptions

  • System.ArgumentException: Thrown when the value is not finite.
  • System.ArgumentOutOfRangeException: Thrown when the value is negative.

Thread Safety

This property is not synchronized. Access it from the main scene thread.

Since

This property is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.AudioStreamPlayer.VolumeDb

Electron2D.AudioStreamPlayer()

Kind: Constructor

public Electron2D.AudioStreamPlayer()

Summary

Initializes a new instance of the Electron2D.AudioStreamPlayer class.

Remarks

The new player has no stream assigned, targets the Master bus and registers the finished signal.

Thread Safety

This constructor is not synchronized. Call it from the main scene thread.

Since

This constructor is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.AudioStreamPlayer.Stream

GetPlaybackPosition()

Kind: Method

public System.Single GetPlaybackPosition()()

Summary

Gets the stored playback position.

Remarks

The preview runtime stores the last requested start or seek position. It does not expose backend clock advancement as public API.

Returns

The stored playback position in seconds.

Thread Safety

This method is not synchronized. Call it from the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.AudioStreamPlayer.Seek(System.Single)

HasStreamPlayback()

Kind: Method

public System.Boolean HasStreamPlayback()()

Summary

Checks whether this player currently owns an active stream voice.

Remarks

This method returns false while Electron2D.AudioStreamPlayer.StreamPaused is true because the preview runtime stops the active voice while preserving the resume position.

Returns

true when at least one internal voice owned by this player is active; otherwise false.

Thread Safety

This method is not synchronized. Call it from the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.AudioStreamPlayer.Playing

Play(System.Single)

Kind: Method

public System.Void Play(System.Single)(System.Single fromPosition)

Summary

Starts playback from a position in the stream.

Remarks

Calling this method creates a new voice when Electron2D.AudioStreamPlayer.Stream is assigned. If Electron2D.AudioStreamPlayer.MaxPolyphony is already reached, the oldest voice owned by this player is stopped first.

Parameters

  • fromPosition: The stream position, in seconds, where playback should begin.

Exceptions

  • System.ArgumentException: Thrown when fromPosition is not finite.
  • System.ArgumentOutOfRangeException: Thrown when fromPosition is negative.

Thread Safety

This method is not synchronized. Call it from the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.AudioStreamPlayer.Seek(System.Single)
  • Electron2D.AudioStreamPlayer.Stop

Seek(System.Single)

Kind: Method

public System.Void Seek(System.Single)(System.Single toPosition)

Summary

Changes the stored playback position.

Remarks

If playback is active and not paused, this method restarts the active voice from toPosition. If playback is paused, the position is used when playback resumes.

Parameters

  • toPosition: The stream position, in seconds, to seek to.

Exceptions

  • System.ArgumentException: Thrown when toPosition is not finite.
  • System.ArgumentOutOfRangeException: Thrown when toPosition is negative.

Thread Safety

This method is not synchronized. Call it from the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.AudioStreamPlayer.GetPlaybackPosition

Stop()

Kind: Method

public System.Void Stop()()

Summary

Stops all voices owned by this player.

Remarks

The stored playback position is reset to 0. Calling Electron2D.AudioStreamPlayer.Stop does not emit the finished signal.

Thread Safety

This method is not synchronized. Call it from the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.AudioStreamPlayer.Play(System.Single)

Clone this wiki locally