Clipboard.SetAudio Method

Definition

Clears the Clipboard and then adds data in the WaveAudio format, replacing the existing data.

Overloads

SetAudio(Byte[])

Clears the Clipboard and then adds a Byte array in the WaveAudio format after converting it to a Stream.

SetAudio(Stream)

Clears the Clipboard and then adds a Stream in the WaveAudio format.

SetAudio(Byte[])

Source:
Clipboard.cs
Source:
Clipboard.cs
Source:
Clipboard.cs

Clears the Clipboard and then adds a Byte array in the WaveAudio format after converting it to a Stream.

C#
public static void SetAudio(byte[] audioBytes);

Parameters

audioBytes
Byte[]

A Byte array containing the audio data.

Exceptions

The Clipboard could not be cleared. This typically occurs when the Clipboard is being used by another process.

The current thread is not in single-threaded apartment (STA) mode. Add the STAThreadAttribute to your application's Main method.

audioBytes is null.

Examples

The following example demonstrates an overload of the SetAudio method that is similar to this overload.

C#
// Demonstrates SetAudio, ContainsAudio, and GetAudioStream.
public System.IO.Stream SwapClipboardAudio(
    System.IO.Stream replacementAudioStream)
{
    System.IO.Stream returnAudioStream = null;
    if (Clipboard.ContainsAudio())
    {
        returnAudioStream = Clipboard.GetAudioStream();
        Clipboard.SetAudio(replacementAudioStream);
    }
    return returnAudioStream;
}

Remarks

To retrieve audio data from the Clipboard, first use the ContainsAudio method to determine whether the Clipboard contains audio data before retrieving it with the GetAudioStream method.

Note

The Clipboard class can only be used in threads set to single thread apartment (STA) mode. To use this class, ensure that your Main method is marked with the STAThreadAttribute attribute.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.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

SetAudio(Stream)

Source:
Clipboard.cs
Source:
Clipboard.cs
Source:
Clipboard.cs

Clears the Clipboard and then adds a Stream in the WaveAudio format.

C#
public static void SetAudio(System.IO.Stream audioStream);

Parameters

audioStream
Stream

A Stream containing the audio data.

Exceptions

The Clipboard could not be cleared. This typically occurs when the Clipboard is being used by another process.

The current thread is not in single-threaded apartment (STA) mode. Add the STAThreadAttribute to your application's Main method.

audioStream is null.

Examples

The following example demonstrates this member.

C#
// Demonstrates SetAudio, ContainsAudio, and GetAudioStream.
public System.IO.Stream SwapClipboardAudio(
    System.IO.Stream replacementAudioStream)
{
    System.IO.Stream returnAudioStream = null;
    if (Clipboard.ContainsAudio())
    {
        returnAudioStream = Clipboard.GetAudioStream();
        Clipboard.SetAudio(replacementAudioStream);
    }
    return returnAudioStream;
}

Remarks

To retrieve audio data from the Clipboard, first use the ContainsAudio method to determine whether the Clipboard contains audio data before retrieving it with the GetAudioStream method.

Note

The Clipboard class can only be used in threads set to single thread apartment (STA) mode. To use this class, ensure that your Main method is marked with the STAThreadAttribute attribute.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.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