SoundEffect.Play Method (Single, Single, Single)

Plays a sound based on specified volume, pitch, and panning.

Namespace: Microsoft.Xna.Framework.Audio
Assembly: Microsoft.Xna.Framework (in microsoft.xna.framework.dll)

public bool Play (
         float volume,
         float pitch,
         float pan
)

Parameters

volume
Type: Single
Volume, ranging from 0.0f (silence) to 1.0f (full volume). 1.0f is full volume relative to SoundEffect.MasterVolume.
pitch
Type: Single
Pitch adjustment, ranging from -1.0f (down one octave) to 1.0f (up one octave). 0.0f is unity (normal) pitch.
pan
Type: Single
Panning, ranging from -1.0f (full left) to 1.0f (full right). 0.0f is centered.

Return Value

true if the sound is playing back successfully; otherwise, false.

Play will return false if there too many sounds already are playing.

To loop a sound or apply 3D effects, call CreateInstance instead of Play, and SoundEffectInstance.Play.

Sounds play in a "fire and forget" fashion with Play; therefore, the lifetime of these sounds is managed by the framework. These sounds will play once, and then stop. They cannot be looped or 3D positioned.

Silverlight applications must ensure that FrameworkDispatcher.Update is called regularly in order for "fire and forget" sounds to work correctly. Play throws an InvalidOperationException if FrameworkDispatcher.Update has not been called at least once before making this call. For more information, see Enable XNA Framework Events in Windows Phone Applications.

Xbox 360, Windows 7, Windows Vista, Windows XP, Windows Phone

Community Additions

ADD
Show: