Difference between revisions of "Global Command: startSound"
From The Official Visionaire Studio: Adventure Game Engine Wiki
m (Text replacement - "{{toc}}" to "") |
|||
Line 1: | Line 1: | ||
− | {| class=" | + | Play an audio file; optionally pass property values. |
− | + | ||
− | + | {| class="ts" | |
|- | |- | ||
− | | | + | | style="width:15%" | Related functions |
+ | | [[Global Command: getSoundId|getSoundId]] | [[Global Command: getSoundProperty|getSoundProperty]] | [[Global Command: setSoundProperty|setSoundProperty]] | [[Global Command: stopSound|stopSound]] | [[Global Command: toggleSoundPause|toggleSoundPause]] | ||
|} | |} | ||
− | + | == Syntax == | |
− | {|class=" | + | <syntaxhighlight lang="lua"> |
+ | startSound(soundfile[, flags]) | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | == Parameters == | ||
+ | |||
+ | {| class="ts" | ||
|- | |- | ||
− | ! | + | ! style="width:15%" | Parameter |
+ | ! style="width:15%" colspan="2" | Type/Structure | ||
+ | ! Description | ||
|- | |- | ||
− | | | + | | soundfile |
+ | | colspan="2" | string | ||
+ | | Relative path to the audio file you want to play. Add the "vispath:" prefix. | ||
|- | |- | ||
− | | | + | | rowspan="5" | flags |
+ | | rowspan="5" | table | ||
+ | | flags = 1 | ||
+ | | indicates flags table | ||
|- | |- | ||
− | | | + | | balance (int) |
+ | | Set left/right audio balance value in the range of -100 (100% left channel) to 100 (100% right channel). | ||
|- | |- | ||
− | | | + | | loop (bool) |
+ | | Set to true to loop the sound. | ||
+ | |- | ||
+ | | offset (int) | ||
+ | | Set the playtime position in milliseconds. | ||
+ | |- | ||
+ | | volume (int) | ||
+ | | Set the volume in the range of 0 (mute) to 100 (full volume). | ||
|} | |} | ||
− | + | == Return values == | |
− | |||
− | |||
− | |||
+ | {| class="ts" | ||
+ | |- | ||
+ | ! style="width:15%" | Type | ||
+ | ! Description | ||
+ | |- | ||
+ | | integer | ||
+ | | Unique id referencing the started sound, or -1 if the sound could not be started. | ||
+ | |} | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | == Examples == | |
− | |||
− | |||
− | + | '''Example 1:''' Play an audio file and store the sound id for later use. Update the left/right balance of the sound while it is playing. | |
− | + | <syntaxhighlight lang="lua"> | |
− | + | local mySoundId = startSound('vispath:sounds/example.ogg') | |
− | + | setSoundProperty(mySoundId, {flags=1, balance=40}) | |
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | '''Example 2:''' Play an audio file and set balance, offset and volume. | |
− | + | <syntaxhighlight lang="lua"> | |
− | + | startSound('vispath:sounds/example.ogg', {flags=1, balance=-10, offset=1000, volume=70}) | |
− | + | </syntaxhighlight> | |
− | + | {{toc}} | |
− | <syntaxhighlight | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | { | ||
− | |||
− | |||
− |
Revision as of 20:38, 4 May 2023
Play an audio file; optionally pass property values.
Related functions | getSoundId | getSoundProperty | setSoundProperty | stopSound | toggleSoundPause |
Syntax
startSound(soundfile[, flags])
Parameters
Parameter | Type/Structure | Description | |
---|---|---|---|
soundfile | string | Relative path to the audio file you want to play. Add the "vispath:" prefix. | |
flags | table | flags = 1 | indicates flags table |
balance (int) | Set left/right audio balance value in the range of -100 (100% left channel) to 100 (100% right channel). | ||
loop (bool) | Set to true to loop the sound. | ||
offset (int) | Set the playtime position in milliseconds. | ||
volume (int) | Set the volume in the range of 0 (mute) to 100 (full volume). |
Return values
Type | Description |
---|---|
integer | Unique id referencing the started sound, or -1 if the sound could not be started. |
Examples
Example 1: Play an audio file and store the sound id for later use. Update the left/right balance of the sound while it is playing.
local mySoundId = startSound('vispath:sounds/example.ogg')
setSoundProperty(mySoundId, {flags=1, balance=40})
Example 2: Play an audio file and set balance, offset and volume.
startSound('vispath:sounds/example.ogg', {flags=1, balance=-10, offset=1000, volume=70})