Audio Class

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Provides methods for playing sounds.

Namespace:   Microsoft.VisualBasic.Devices
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

System.Object
  Microsoft.VisualBasic.Devices.Audio

[HostProtectionAttribute(SecurityAction.LinkDemand, Resources = HostProtectionResource.ExternalProcessMgmt)]
public class Audio

NameDescription
System_CAPS_pubmethodAudio()

Initializes a new instance of the Audio class.

NameDescription
System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodPlay(Byte[], AudioPlayMode)

Plays a .wav sound file.

System_CAPS_pubmethodPlay(Stream, AudioPlayMode)

Plays a .wav sound file.

System_CAPS_pubmethodPlay(String)

Plays a .wav sound file.

System_CAPS_pubmethodPlay(String, AudioPlayMode)

Plays a .wav sound file.

System_CAPS_pubmethodPlaySystemSound(SystemSound)

Plays a system sound.

System_CAPS_pubmethodStop()

Stops a sound playing in the background.

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

You can use the My.Computer.Audio.Play and My.Computer.Audio.PlaySystemSound methods to play .wav sound files and system sounds.

For more information, see Playing Sounds (Visual Basic).

Project type

Available

Windows Application

Yes

Class Library

Yes

Console Application

Yes

Windows Control Library

Yes

Web Control Library

No

Windows Service

Yes

Web Site

No

The My.Computer.Audio.Play method plays the specified sound in the background when AudioPlayMode.Background is specified.

Sub PlayBackgroundSoundFile()
    My.Computer.Audio.Play("C:\Waterfall.wav", 
        AudioPlayMode.WaitToComplete)
End Sub

This code can run only within a Windows Forms application.

The file name should reference a .wav sound file on your system.

To simplify the management of your sound files, consider storing the files as application resources. The files can then be accessed through the My.Resources object.

.NET Framework
Available since 2.0

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: