Controls playback of a sound from a .wav file.
Assembly: System (in System.dll)
Thetype exposes the following members.
|SoundPlayer()||Initializes a new instance of the class.|
|SoundPlayer(Stream)||Initializes a new instance of the class, and attaches the .wav file within the specified Stream.|
|SoundPlayer(String)||Initializes a new instance of the class, and attaches the specified .wav file.|
|SoundPlayer(SerializationInfo, StreamingContext)||Initializes a new instance of the class.|
|CanRaiseEvents||Gets a value indicating whether the component can raise an event. (Inherited from Component.)|
|Container||Gets the IContainer that contains the Component. (Inherited from Component.)|
|DesignMode||Gets a value that indicates whether the Component is currently in design mode. (Inherited from Component.)|
|Events||Gets the list of event handlers that are attached to this Component. (Inherited from Component.)|
|IsLoadCompleted||Gets a value indicating whether loading of a .wav file has successfully completed.|
|LoadTimeout||Gets or sets the time, in milliseconds, in which the .wav file must load.|
|Site||Gets or sets the ISite of the Component. (Inherited from Component.)|
|SoundLocation||Gets or sets the file path or URL of the .wav file to load.|
|Stream||Gets or sets the Stream from which to load the .wav file.|
|Tag||Gets or sets the Object that contains data about the .|
|CreateObjRef||Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)|
|Dispose()||Releases all resources used by the Component. (Inherited from Component.)|
|Dispose(Boolean)||Releases the unmanaged resources used by the Component and optionally releases the managed resources. (Inherited from Component.)|
|Equals(Object)||Determines whether the specified object is equal to the current object. (Inherited from Object.)|
|Finalize||Releases unmanaged resources and performs other cleanup operations before the Component is reclaimed by garbage collection. (Inherited from Component.)|
|GetHashCode||Serves as the default hash function. (Inherited from Object.)|
|GetLifetimeService||Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)|
|GetService||Returns an object that represents a service provided by the Component or by its Container. (Inherited from Component.)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|InitializeLifetimeService||Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)|
|Load||Loads a sound synchronously.|
|LoadAsync||Loads a .wav file from a stream or a Web resource using a new thread.|
|MemberwiseClone()||Creates a shallow copy of the current Object. (Inherited from Object.)|
|MemberwiseClone(Boolean)||Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)|
|OnLoadCompleted||Raises the LoadCompleted event.|
|OnSoundLocationChanged||Raises the SoundLocationChanged event.|
|OnStreamChanged||Raises the StreamChanged event.|
|Play||Plays the .wav file using a new thread, and loads the .wav file first if it has not been loaded.|
|PlayLooping||Plays and loops the .wav file using a new thread, and loads the .wav file first if it has not been loaded.|
|PlaySync||Plays the .wav file and loads the .wav file first if it has not been loaded.|
|Stop||Stops playback of the sound if playback is occurring.|
|ToString||Returns a String containing the name of the Component, if any. This method should not be overridden. (Inherited from Component.)|
|Disposed||Occurs when the component is disposed by a call to the Dispose method. (Inherited from Component.)|
|LoadCompleted||Occurs when a .wav file has been successfully or unsuccessfully loaded.|
|SoundLocationChanged||Occurs when a new audio source path for this has been set.|
|StreamChanged||Occurs when a new Stream audio source for this has been set.|
The class provides a simple interface for loading and playing a .wav file. The class supports loading a .wav file from a file path, a URL, a Stream that contains a .wav file, or an embedded resource that contains a .wav file.
To play a sound using the class, configure a with a path to the .wav file and call one of the play methods. You can identify the .wav file to play by using one of the constructors or by setting either the SoundLocation or Stream property. The file can be loaded prior to playing by using one of the load methods, or loading can be deferred until one of the play methods is called. A configured to load a .wav file from a Stream or URL must load the .wav file into memory before playback begins.
You can load or play a .wav file synchronously or asynchronously. If you call a synchronous load or play method, the calling thread will wait until the method returns, which may cause painting and other events to be interrupted. Calling an asynchronous load or play method will allow the calling thread to continue without interruption. For more information on asynchronous method calls, see How to: Run an Operation in the Background.
When a has finished loading a .wav file, it raises the LoadCompleted event. You can examine the AsyncCompletedEventArgs in your event handler to determine if the load succeeded or failed. The SoundLocationChanged event is raised when the audio source is set to a new file path or URL. The StreamChanged event is raised when the audio source is set to a new Stream. For more information about handling events, see Consuming Events.
For more information about , see SoundPlayer Class Overview.
The class cannot play other file types, such as .wma or .mp3. If you want to play other file types, you can use the Windows Media Player control. For more information, see Using the Windows Media Player Control in a .NET Framework Solution and Windows Media Player Object Model Reference for Visual Basic .NET and C# in the Windows Media Player SDK.
The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: UI. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.