Udostępnij za pośrednictwem


How to: Stop Playing Sounds in the Background in Visual Basic

This example stops a sound playing in the background.

Background playing lets the application execute other code while the sound plays. For more information, see How to: Play Looping Sounds in Visual Basic and How to: Play Sounds in Visual Basic.

In general, when an application plays a looping sound, it should stop the sound at some point.

Example

Use the My.Computer.Audio.Stop method to stop the application's currently playing background or looping sound.

Sub StopBackgroundSound()
    My.Computer.Audio.Stop()
End Sub

This code example is also available as an IntelliSense code snippet. In the code snippet picker, it is located in Windows Forms Applications > Sound. For more information, see How to: Insert Snippets Into Your Code (Visual Basic).

Compiling the Code

This code example can run only within a Windows Forms or console application. For more information, see My.Computer.Audio.Stop Method.

See Also

Tasks

How to: Play Sounds in Visual Basic

How to: Determine if a File Exists in Visual Basic

Reference

My.Computer.Audio.Stop Method

Other Resources

Playing Sounds