Difference between revisions of "Sound"
From Xojo Documentation
(→See Also) |
|||
Line 15: | Line 15: | ||
<dynamicTable id="Methods" class="methodTable" title="Methods" columns="3"> | <dynamicTable id="Methods" class="methodTable" title="Methods" columns="3"> | ||
{{Method | name=Clone | returntype=[[Sound]] | newinversion=5.5 | description=Clone() as '''Sound'''
Returns a clone of the sound as a Sound, but can be played, stopped, and modified independently of the original sound }} | {{Method | name=Clone | returntype=[[Sound]] | newinversion=5.5 | description=Clone() as '''Sound'''
Returns a clone of the sound as a Sound, but can be played, stopped, and modified independently of the original sound }} | ||
+ | {{Method | name=Handle | returntype=[[Ptr]] | description=Handle() as Ptr
On iOS, returns a Ptr to the underlying AVAudioPlayer object. }} | ||
{{Method | name=IsPlaying | returntype=[[Boolean]] | description=IsPlaying() as Boolean
Returns True if the sound is playing. }} | {{Method | name=IsPlaying | returntype=[[Boolean]] | description=IsPlaying() as Boolean
Returns True if the sound is playing. }} | ||
{{Method | name=Play | description=Play()
Plays the sound. }} | {{Method | name=Play | description=Play()
Plays the sound. }} |
Revision as of 21:28, 2 March 2021
Used to play sounds.
Properties | ||
|
Methods | ||||||
|
Shared Methods | |
|
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:
This code loads a sound file called "TaDa.mp3" from the desktop into a sound object and plays it.
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.
This code stops "Giggle".
See Also
NotePlayer control.