Class

# Sound

<div class="rst-class">

forsearch

</div>

Sound

<div class="rst-class">

forsearch

</div>

Music

<div class="rst-class">

forsearch

</div>

Audio

<div class="rst-class">

forsearch

</div>

Media

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Used to play sounds.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                   | Type                               | Read-Only | Shared |
|------------------------|------------------------------------|-----------|--------|
| `Pan<sound.pan>`       | `Integer</api/data_types/integer>` |           |        |
| `Rate<sound.rate>`     | `Double</api/data_types/double>`   |           |        |
| `Volume<sound.volume>` | `Integer</api/data_types/integer>` |           |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                             | Parameters                                       | Returns                                     | Shared |
|----------------------------------|--------------------------------------------------|---------------------------------------------|--------|
| `Clone<sound.clone>`             |                                                  | Sound                                       |        |
| `Handle<sound.handle>`           |                                                  | `Ptr</api/data_types/additional_types/ptr>` |        |
| `IsPlaying<sound.isplaying>`     |                                                  | `Boolean</api/data_types/boolean>`          |        |
| `Open<sound.open>`               | soundFile As `FolderItem</api/files/folderitem>` | Sound                                       | ✓      |
| `Play<sound.play>`               |                                                  |                                             |        |
| `PlayLooping<sound.playlooping>` |                                                  |                                             |        |
| `Stop<sound.stop>`               |                                                  |                                             |        |

## Property descriptions

<div id="sound.pan">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Sound.Pan

**Pan** As `Integer</api/data_types/integer>`

> Specifies the relative volume (balance) between the left and right speakers.
>
> The range is from -100 to +100, with 0 indicating equal volume in the left and right channels. -100 plays <span class="title-ref">Sound</span> in the left channel only; 100 plays <span class="title-ref">Sound</span> in the right channel only. The default is 0.

<div id="sound.rate">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Sound.Rate

**Rate** As `Double</api/data_types/double>`

> Controls the playback speed of the <span class="title-ref">Sound</span>. Default is 1.0.

<div id="sound.volume">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Sound.Volume

**Volume** As `Integer</api/data_types/integer>`

> Controls the volume of the <span class="title-ref">Sound</span>.
>
> The range is from 0 to 100; 0 mutes the <span class="title-ref">Sound</span> and 100 plays the <span class="title-ref">Sound</span> at the "normal" volume set in the computer's volume setting. Default is 100.

## Method descriptions

<div id="sound.clone">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Sound.Clone

**Clone** As Sound

> Returns a clone of the <span class="title-ref">Sound</span> as a <span class="title-ref">Sound</span>, but can be played, stopped, and modified independently of the original <span class="title-ref">Sound</span>.
>
> Use Clone instead of opening the same <span class="title-ref">Sound</span> file twice, because Clone is likely to be substantially more efficient.
>
> This example clones a <span class="title-ref">Sound</span> that has been added to the project and plays it.
>
> ``` xojo
> Var mySound As New Sound
> mySound= chimes.Clone
> mySound.pan = pan.Value
> mySound.volume = VolumeValue.Value
> mySound.Play
> ```

<div id="sound.handle">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Sound.Handle

**Handle** As `Ptr</api/data_types/additional_types/ptr>`

> Returns a `Ptr</api/data_types/additional_types/ptr>` to the underlying OS <span class="title-ref">Sound</span> object for use with `Declares</api/language/declare>`.
>
> On iOS, returns a `Ptr</api/data_types/additional_types/ptr>` to the underlying AVAudioPlayer object.
>
> <div class="important">
>
> <div class="title">
>
> Important
>
> </div>
>
> This method is not supported for Android.
>
> </div>

<div id="sound.isplaying">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Sound.IsPlaying

**IsPlaying** As `Boolean</api/data_types/boolean>`

> Returns `True</api/language/true>` if the <span class="title-ref">Sound</span> is playing.
>
> This example stops a <span class="title-ref">Sound</span> that was played using PlayLooping. It checks to see if the <span class="title-ref">Sound</span> is still playing.
>
> ``` xojo
> If chimes.IsPlaying Then
>   chimes.Stop
> End If
> ```

<div id="sound.open">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Sound.Open

**Open**(soundFile As `FolderItem</api/files/folderitem>`) As Sound

> Opens the FolderItem to be read and returns its contents as a <span class="title-ref">Sound</span> object.
>
> This method is `shared</api/language/shared>`.
>
> On macOS, the <span class="title-ref">Sound</span> class recognizes <span class="title-ref">Sound</span> formats that [Core Audio can play](https://developer.apple.com/library/ios/documentation/MusicAudio/Conceptual/CoreAudioOverview/SupportedAudioFormatsMacOSX/SupportedAudioFormatsMacOSX.html).
>
> The Open method is not support for iOS.
>
> On Windows WAVs, WMAs, MP3s, and MIDI files can be played, but only WAVs play with [DirectSound](http://msdn.microsoft.com/en-us/library/windows/desktop/ee416960(v=vs.85).aspx) (this allows individual pan and volume settings for each <span class="title-ref">Sound</span>. You can also play multiple sounds simultaneously).
>
> On Linux [GStreamer](http://gstreamer.freedesktop.org), [xine](http://www.xine-project.org/home), or [libsndfile](http://en.wikipedia.org/wiki/Libsndfile) is used (in that order if available). `Nil</api/language/nil>` is returned if the <span class="title-ref">Sound</span> can't be read or isn't a <span class="title-ref">Sound</span> file at all.
>
> This example loads a <span class="title-ref">Sound</span> file called “hello.mp3” from the desktop into a <span class="title-ref">Sound</span> object and plays it.
>
> ``` xojo
> Var f As FolderItem = SpecialFolder.Desktop.Child("hello.mp3")
> If f <> Nil And f.Exists Then
>   Var s As Sound
>   s = s.Open(f)
>   s.Play
> End If
> ```

<div id="sound.play">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Sound.Play

**Play**

> Plays the <span class="title-ref">Sound</span>.

<div id="sound.playlooping">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Sound.PlayLooping

**PlayLooping**

> Plays the <span class="title-ref">Sound</span> in an infinite loop.
>
> Playlooping can be called instead of Play when you want an indefinite <span class="title-ref">Sound</span>.
>
> ``` xojo
> chimes.PlayLooping
> ```

<div id="sound.stop">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Sound.Stop

**Stop**

> Stops a <span class="title-ref">Sound</span> that is playing.
>
> Stop can be called to stop a <span class="title-ref">Sound</span> that was played by PlayLooping.
>
> ``` xojo
> chimes.Stop
> ```

## 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<sound.open>` method of a <span class="title-ref">Sound</span>.

Sound can play <span class="title-ref">Sound</span> formats and simultaneous sounds as determined by the system.

On Windows, <span class="title-ref">Sound</span> can play a variety of <span class="title-ref">Sound</span> formats but can only play WAV sounds simultaneously.

On Linux, <span class="title-ref">Sound</span> uses GStreamer (requires version 0.10+) by default, which supports a wide range of [Sound formats](https://gstreamer.freedesktop.org/documentation/plugin-development/advanced/media-types.html#table-of-audio-types). [Xine](https://en.wikipedia.org/wiki/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](https://developer.apple.com/library/archive/documentation/MusicAudio/Conceptual/CoreAudioOverview/SupportedAudioFormatsMacOSX/SupportedAudioFormatsMacOSX.html).

## Sample code

This code plays a <span class="title-ref">Sound</span> called "SledgeHammer" which has been added to the project:

``` xojo
SledgeHammer.Play
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

This code loads a <span class="title-ref">Sound</span> file called "TaDa.mp3" from the desktop into a <span class="title-ref">Sound</span> object and plays it.

``` xojo
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 <span class="title-ref">Sound</span> "Giggle", which has been added to the project, in an endless loop.

``` xojo
Giggle.PlayLooping
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

This code stops "Giggle".

``` xojo
Giggle.Stop
```

## Compatibility

|                       |                 |
|-----------------------|-----------------|
| **Project Types**     | Desktop, Mobile |
| **Operating Systems** | All             |

<div class="seealso">

`Object</api/data_types/additional_types/object>` parent class; `DesktopNotePlayer</api/user_interface/desktop/desktopnoteplayer>` control.

</div>
