Sound

From Xojo Documentation

Class (inherits from Object)

Used to play sounds.

Properties
Pan Volume


Methods
Clone Play Stop
IsPlaying PlayLooping
Shared Methods
Open

Notes

Sounds that have been added to the project can be accessed via their object name. Sounds can also be loaded from disk by calling the Open method of a Sound.

Sound can play sound formats and simultaneous sounds as determined by the system.

On Windows, Sound can play a variety of sound formats but can only play WAV sounds simultaneously.

On Linux, Sound uses GStreamer (requires version 0.10+) by default, which supports a wide range of sound formats. Xine is used when GStreamer is not available.

On macOS, AVFoundation is used to play sounds with support for a wide variety of sound formats.

Examples

This code plays a sound called "SledgeHammer" which has been added to the project:

SledgeHammer.Play

This code loads a sound file called "TaDa.mp3" from the desktop into a sound object and plays it.

Var soundFile As FolderItem = SpecialFolder.Desktop.Child("TaDa.mp3")
If soundFile.Exists Then
Try
Var tada As Sound = Sound.Open(soundFile)
tada.Play
Catch error As IOException
MessageBox("The sound file could not be opened. Error: " + error.Message)
End Try
End If

The following code plays the sound "Giggle", which has been added to the project, in an endless loop.

Giggle.PlayLooping

This code stops "Giggle".

Giggle.Stop

See Also

NotePlayer control.