Sound

From Xojo Documentation

Class (inherits from Object)

Used to play sounds.

Properties
Pan Volume


Methods
Clone Play Stop
IsPlaying PlayLooping

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 OpenAsSound method of a FolderItem.

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 example plays a sound called "SledgeHammer" which has been added to the project:

SledgeHammer.Play

This example loads a sound file called "Doh!" from the current directory (folder) into a sound object and plays it.

Dim f As FolderItem = GetFolderItem("Doh!")
If f <> Nil Then
Dim s As Sound = f.OpenAsSound
If s <> Nil Then
s.Play
Else
// check f.LastErrorCode
End If
Else
// user cancelled
End If

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

Giggle.PlayLooping

This example stops "Giggle".

Giggle.Stop

See Also

NotePlayer control.