Plays a .wav sound file.
' Usage My.Computer.Audio.Play(location) My.Computer.Audio.Play(location ,playMode) My.Computer.Audio.Play(data ,playMode) My.Computer.Audio.Play(stream ,playMode) ' Declaration Public Sub Play( _ ByVal location As String _ ) ' -or- Public Sub Play( _ ByVal location As String, _ ByVal playMode As AudioPlayMode _ ) ' -or- Public Sub Play( _ ByVal data As Byte(), _ ByVal playMode As AudioPlayMode _ ) ' -or- Public Sub Play( _ ByVal stream As System.IO.Stream, _ ByVal playMode As AudioPlayMode _ )
The following conditions can cause an exception:
The data or stream is Nothing, or location is an empty string (ArgumentNullException).
The user does not have sufficient permissions to access the file named by location (IOException).
The file path is malformed in location (DirectoryNotFoundException)
The path name in location is too long (PathTooLongException)
A partial-trust situation exists in which the user lacks necessary permissions (SecurityException).
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 My.Computer.Audio.Stop Method is called. The calling code continues to execute.
Plays the sound and waits until it completes before the calling code continues.
The following table lists examples of tasks involving the My.Computer.Audio.Play method.
Play a sound once
Play a sound many times
Play a sound in the background
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.
Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)
Availability by Project Type
Windows Control Library
Web Control Library
The following permissions may be necessary:
Controls the ability to access files and folders. Associated enumeration: Unrestricted.
Describes a set of security permissions applied to code. Associated enumeration: ControlThread.