FutureBasic Logo

<<    Index    >> FutureBasic

sound   statement / function / object



Statement syntax
[ result = ] sound [-]tag, [ name ] [, { url | data | pasteboard } [, volume [, loops ] ] ]
[ result = ] sound stop tag
sound close tag

Function syntax
isPlaying = sound(tag)
 
Description
The sound statement and/or the functions in the Sound.incl header play system sounds or audio files such as mp4 and m4a. Use the sound stop statement to stop a sound playing, and the sound close statement to remove the sound from FB's list of stored sounds. The sound function is used to determine if a sound is currently playing.
 
Parameters
Parameter
Description
tag A number assigned when the sound is created and referred to when altering a sound. A negative tag pauses the sound. To resume a paused sound, use a positive tag value.
name The name of the sound as a CFString expression.
url
data
pasteboard
Initializes the sound with the audio data located at a given URL.
Initializes the sound with the given audio data.
Initializes the sound with the data from a pasteboard.
volume The sound volume. A double value in the range 0.0 to 1.0.
loops A boolean of YES sets looping ON while a boolean of NO sets looping OFF.
 
Return values
The optional result boolean values returned by sound and sound stop statements indicates success (YES) or failure (NO). The isPlaying boolean value (of YES) returned from the sound function indicates the sound is currently playing.
 

Example 1

// play a system sound
sound 1, @"Purr"

Example 2

// play app resource sound at half volume and loop
sound 1, @"MySound",, 0.5, YES

Example 3

// play a sound file
sound 1,, url

Example 4

// we can also play a sound without the use of the 'sound' keyword
fn SoundPlay( fn SoundNamed( @"MySound" ) )

 
Dialog event
_soundDidFinishPlaying

See
The Sound.incl header for many other "Sound" related calls
 
Note
For more sophisticated control of sounds, the AVAudioEngine/AVAudioPlayer are available.
 
Apple documentation
NSSound