Table of Contents

Class SoundEffectInstanceHandler

Namespace
MLEM.Sound
Assembly
MLEM.dll

A simple class that handles automatically removing and disposing Microsoft.Xna.Framework.Audio.SoundEffectInstance objects once they are done playing to free up the audio source for new sounds. Additionally, a callback can be registered that is invoked when the Microsoft.Xna.Framework.Audio.SoundEffectInstance finishes playing. Note that an object of this class can be added to a Microsoft.Xna.Framework.Game using its Microsoft.Xna.Framework.GameComponentCollection.

public class SoundEffectInstanceHandler : GameComponent, IGameComponent, IUpdateable, IDisposable, IEnumerable<SoundEffectInstanceHandler.Entry>, IEnumerable
Inheritance
GameComponent
SoundEffectInstanceHandler
Implements
IGameComponent
IUpdateable
Inherited Members
GameComponent.Initialize()
GameComponent.Dispose()
GameComponent.Game
GameComponent.Enabled
GameComponent.UpdateOrder
GameComponent.EnabledChanged
GameComponent.UpdateOrderChanged
Extension Methods

Constructors

SoundEffectInstanceHandler(Game)

Creates a new sound effect instance handler with the given settings

public SoundEffectInstanceHandler(Game game)

Parameters

game Game

The game instance

Methods

Add(SoundEffectInfo, Action<SoundEffectInstance>, AudioEmitter)

Adds a new SoundEffectInfo to this handler. This also starts playing the created instance.

public SoundEffectInstance Add(SoundEffectInfo info, Action<SoundEffectInstance> onStopped = null, AudioEmitter emitter = null)

Parameters

info SoundEffectInfo

The info for which to add a Microsoft.Xna.Framework.Audio.SoundEffectInstance

onStopped Action<SoundEffectInstance>

The function that should be invoked when this instance stops playing, defaults to null

emitter AudioEmitter

An optional audio emitter with which 3d sound can be applied

Returns

SoundEffectInstance

The newly created Microsoft.Xna.Framework.Audio.SoundEffectInstance

Add(SoundEffect, Action<SoundEffectInstance>, AudioEmitter)

Adds a new Microsoft.Xna.Framework.Audio.SoundEffect to this handler. This also starts playing the created instance.

public SoundEffectInstance Add(SoundEffect effect, Action<SoundEffectInstance> onStopped = null, AudioEmitter emitter = null)

Parameters

effect SoundEffect

The sound for which to add a Microsoft.Xna.Framework.Audio.SoundEffectInstance

onStopped Action<SoundEffectInstance>

The function that should be invoked when this instance stops playing, defaults to null

emitter AudioEmitter

An optional audio emitter with which 3d sound can be applied

Returns

SoundEffectInstance

The newly created Microsoft.Xna.Framework.Audio.SoundEffectInstance

Add(SoundEffectInstance, Action<SoundEffectInstance>, AudioEmitter)

Adds a new Microsoft.Xna.Framework.Audio.SoundEffectInstance to this handler. This also starts playing the instance.

public SoundEffectInstance Add(SoundEffectInstance instance, Action<SoundEffectInstance> onStopped = null, AudioEmitter emitter = null)

Parameters

instance SoundEffectInstance

The instance to add

onStopped Action<SoundEffectInstance>

The function that should be invoked when this instance stops playing, defaults to null

emitter AudioEmitter

An optional audio emitter with which 3d sound can be applied

Returns

SoundEffectInstance

The passed instance, for chaining

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<SoundEffectInstanceHandler.Entry> GetEnumerator()

Returns

IEnumerator<SoundEffectInstanceHandler.Entry>

An enumerator that can be used to iterate through the collection.

Pause()

Pauses all of the sound effect instances that are currently playing

public void Pause()

Resume()

Resumes all of the sound effect instances in this handler

public void Resume()

SetListeners(params AudioListener[])

Sets the collection Microsoft.Xna.Framework.Audio.AudioListener objects that should be listening to the sounds in this handler in 3D space. If there are one or more listeners, this handler applies 3d effects to all sound effect instances that have been added to this handler along with an Microsoft.Xna.Framework.Audio.AudioEmitter in Update(GameTime) automatically.

public void SetListeners(params AudioListener[] listeners)

Parameters

listeners AudioListener[]

Stop()

Stops all of the sound effect instances in this handler

public void Stop()

Update()

Updates this sound effect handler and manages all of the Microsoft.Xna.Framework.Audio.SoundEffectInstance objects in it. If SetListeners(params AudioListener[]) has been called, all sounds will additionally be updated in 3D space. This should be called each update frame.

public void Update()

Update(GameTime)

Updates this sound effect handler and manages all of the Microsoft.Xna.Framework.Audio.SoundEffectInstance objects in it. If SetListeners(params AudioListener[]) has been called, all sounds will additionally be updated in 3D space. This should be called each update frame.

public override void Update(GameTime gameTime)

Parameters

gameTime GameTime