System 2.0.0.0 4.0.0.0 System.ComponentModel.Component System.Runtime.Serialization.ISerializable System.ComponentModel.ToolboxItem(false)

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 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 or 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 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 event. You can examine the in your event handler to determine if the load succeeded or failed. The event is raised when the audio source is set to a new file path or URL. The event is raised when the audio source is set to a new . For more information about handling events, see Consuming Events.

For more information about , see SoundPlayer Class Overview (Windows Forms).

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.

Controls playback of a sound from a .wav file.

- Constructor
  2.0.0.0
  4.0.0.0

  This constructor initializes a with no audio source. Until it is configured with an audio source path, the will play a beep sound when one of its playback methods is called.

  Initializes a new instance of the class.

- Constructor
  2.0.0.0
  4.0.0.0

  The passed to the parameter should be a containing a .wav file. The data returned by the method of the should be the data within a .wav file.

  Initializes a new instance of the class, and attaches the .wav file within the specified .

  A to a .wav file.
- Constructor
  2.0.0.0
  4.0.0.0

  The string passed to the parameter can be either a file path or a URL to a .wav file. If the path or URL is not valid, the will still be constructed, but subsequent calls to a load or play method will fail.

  Initializes a new instance of the class, and attaches the specified .wav file.

  The location of a .wav file to load.
- Constructor
  2.0.0.0
  4.0.0.0
  To be added.

  Initializes a new instance of the class.

  The to be used for deserialization.
  The destination to be used for deserialization.
- Property
  2.0.0.0
  4.0.0.0
  System.Boolean To be added. To be added.

  Gets a value indicating whether loading of a .wav file has successfully completed.

- Method
  2.0.0.0
  4.0.0.0
  System.Void

  The method uses the current thread to load a .wav file, preventing the thread from handling other messages until the load is complete.

  The method may produce a delay while loading a large .wav file. In addition, painting and other events will be blocked until the load is completed. Use the method to load a sound asynchronously, which allows the calling thread to continue without interruption.

  This method raises the event when loading completes, even if the load was not successful.

  Loads a sound synchronously.

- Method
  2.0.0.0
  4.0.0.0
  System.Void

  If a is configured to load a .wav file from a or Web resource, this method begins loading a .wav file from the location using a new thread.

  This method raises the event when loading completes, even if the load was not successful.

  If a is configured to load a .wav file from a local file path, this method does nothing, because loading is deferred until playing begins.

  For more information about asynchronous loading, see How to: Load a Sound Asynchronously within a Windows Form.

  Loads a .wav file from a stream or a Web resource using a new thread.

- Event
  2.0.0.0
  4.0.0.0
  System.ComponentModel.AsyncCompletedEventHandler

  This event is raised when loading of a .wav file is complete. The event arguments indicate whether the load of the sound was completed successfully or failed.

  For more information about handling events, see Consuming Events.

  Occurs when a .wav file has been successfully or unsuccessfully loaded.

- Property
  2.0.0.0
  4.0.0.0
  System.Int32 To be added.

  After this time has expired, the loading is canceled and a exception is thrown.

  Gets or sets the time, in milliseconds, in which the .wav file must load.

- Method
  2.0.0.0
  4.0.0.0
  System.Void ``

  This method is called when loading of a .wav file is complete.

  Raising an event invokes the event handler through a delegate. For more information, see Raising an Event.

  The method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.

  Raises the event.

  An that contains the event data.
- Method
  2.0.0.0
  4.0.0.0
  System.Void ``

  This method is called when a new audio source path for this has been set.

  Raising an event invokes the event handler through a delegate. For more information, see How to: Provide Event functionality and Raising an Event.

  The method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.

  Raises the event.

  An that contains the event data.
- Method
  2.0.0.0
  4.0.0.0
  System.Void ``

  This method is called when a new audio source for this has been set.

  Raising an event invokes the event handler through a delegate. For more information, see Raising an Event.

  The method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.

  Raises the event.

  An that contains the event data.
- Method
  2.0.0.0
  4.0.0.0
  System.Void

  The method plays the sound using a new thread. If you call before the .wav file has been loaded into memory, the .wav file will be loaded before playback starts. You can use the or method to load the .wav file to memory in advance. After a .wav file is successfully loaded from a or URL, future calls to playback methods for the will not need to reload the .wav file until the path for the sound changes.

  If the .wav file has not been specified or it fails to load, the method will play the default beep sound.

  Plays the .wav file using a new thread, and loads the .wav file first if it has not been loaded.

- Method
  2.0.0.0
  4.0.0.0
  System.Void

  The method plays and loops the sound using a new thread. If you call before the .wav file has been loaded into memory, the .wav file will be loaded before playback starts. You can use the or method to load the .wav file to memory in advance. After a .wav file is successfully loaded from a or URL, future calls to playback methods for the will not need to reload the .wav file until the path for the sound changes.

  If the .wav file has not been specified or it fails to load, the method will play the default beep sound.

  For more information about , see How to: Loop a Sound Playing on a Windows Form.

  Plays and loops the .wav file using a new thread, and loads the .wav file first if it has not been loaded.

- Method
  2.0.0.0
  4.0.0.0
  System.Void

  The method uses the current thread to play a .wav file, preventing the thread from handling other messages until the load is complete. You can use the or method to load the .wav file to memory in advance. After a .wav file is successfully loaded from a or URL, future calls to playback methods for the will not need to reload the .wav file until the path for the sound changes.

  If the .wav file has not been specified or it fails to load, the method will play the default beep sound.

  Plays the .wav file and loads the .wav file first if it has not been loaded.

- Property
  2.0.0.0
  4.0.0.0
  System.String To be added.

  This property is set to when the property is set to a .

  Gets or sets the file path or URL of the .wav file to load.

- Event
  2.0.0.0
  4.0.0.0
  System.EventHandler

  This event is raised when a new audio source path for this has been set.

  For more information about handling events, see Consuming Events.

  Occurs when a new audio source path for this has been set.

- Method
  2.0.0.0
  4.0.0.0
  System.Void To be added.

  Stops playback of the sound if playback is occurring.

- Property
  2.0.0.0
  4.0.0.0
  System.IO.Stream To be added.

  This property is set to null when the property is set to a new and valid sound location.

  Gets or sets the from which to load the .wav file.

- Event
  2.0.0.0
  4.0.0.0
  System.EventHandler

  This event is raised when a new audio source for this has been set.

  For more information about handling events, see Consuming Events.

  Occurs when a new audio source for this has been set.

- Method
  2.0.0.0
  4.0.0.0
  System.Void `` ``

  This member is an explicit interface member implementation. It can be used only when the instance is cast to an interface.

  For a description of this member, see the method.

  The to populate with data. The destination (see ) for this serialization.
- Property
  2.0.0.0
  4.0.0.0
  System.Object To be added. To be added.

  Gets or sets the that contains data about the .