SoundPlayer Constructors

Definition

Initializes a new instance of the SoundPlayer class.

Overloads

SoundPlayer()

Initializes a new instance of the SoundPlayer class.

SoundPlayer(Stream)

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

SoundPlayer(String)

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

SoundPlayer(SerializationInfo, StreamingContext)
Obsolete.

Initializes a new instance of the SoundPlayer class.

SoundPlayer()

Source:
SoundPlayer.cs
Source:
SoundPlayer.cs
Source:
SoundPlayer.cs
Source:
SoundPlayer.cs
Source:
SoundPlayer.cs

Initializes a new instance of the SoundPlayer class.

C#
public SoundPlayer();

Remarks

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

See also

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

SoundPlayer(Stream)

Source:
SoundPlayer.cs
Source:
SoundPlayer.cs
Source:
SoundPlayer.cs
Source:
SoundPlayer.cs
Source:
SoundPlayer.cs

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

C#
public SoundPlayer(System.IO.Stream? stream);
C#
public SoundPlayer(System.IO.Stream stream);

Parameters

stream
Stream

A Stream to a .wav file.

Remarks

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

See also

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

SoundPlayer(String)

Source:
SoundPlayer.cs
Source:
SoundPlayer.cs
Source:
SoundPlayer.cs
Source:
SoundPlayer.cs
Source:
SoundPlayer.cs

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

C#
public SoundPlayer(string soundLocation);

Parameters

soundLocation
String

The location of a .wav file to load.

Exceptions

The URL value specified by soundLocation cannot be resolved.

Remarks

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

See also

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

SoundPlayer(SerializationInfo, StreamingContext)

Source:
SoundPlayer.cs
Source:
SoundPlayer.cs
Source:
SoundPlayer.cs
Source:
SoundPlayer.cs
Source:
SoundPlayer.cs

Caution

This API supports obsolete formatter-based serialization. It should not be called or extended by application code.

Initializes a new instance of the SoundPlayer class.

C#
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected SoundPlayer(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext context);
C#
protected SoundPlayer(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext context);

Parameters

serializationInfo
SerializationInfo

The SerializationInfo to be used for deserialization.

context
StreamingContext

The destination to be used for deserialization.

Attributes

Exceptions

The SoundLocation specified in serializationInfo cannot be resolved.

See also

Applies to

.NET 10 (package-provided) and other versions
Product Versions (Obsolete)
.NET (8 (package-provided), 9 (package-provided), 10 (package-provided))
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7 (8, 9, 10)