Audio.Play Method (String)
Plays a .wav sound file.
Assembly: Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)
location is an empty string.
The user does not have sufficient permissions to access the file named by location.
The file path is malformed in location.
The path name in location is too long.
A partial-trust situation exists in which the user lacks necessary permissions.
The Play method plays the .wav sound file stored as a file at location, as a byte array in data, or as a stream in stream.
If the overload that takes only the location parameter is used, the Play method plays the sound in the background. Otherwise, the playMode parameter determines how the sound will play.
Plays the sound in the background. The calling code continues to execute.
Plays the sound in the background until the Stop method is called. The calling code continues to execute.
Plays the sound and waits until it completes before the calling code continues.
Background playing lets the application execute other code while the sound plays.
For more information, see Playing Sounds (Visual Basic).
Availability by Project Type
Windows Control Library
Web Control Library
The My.Computer.Audio.Play method plays the specified sound in the background when PlayMode.Background is specified.
This code example can only run 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. They can then be accessed through the My.Resources object.
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)