GetSoundLength: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
m (Reverted edits by Ameir (talk) to last revision by Alvesvin)
Tag: Rollback
 
(10 intermediate revisions by 8 users not shown)
Line 2: Line 2:
{{Client function}}
{{Client function}}
This function is used to return the playback length of the specified [[sound]] element.
This function is used to return the playback length of the specified [[sound]] element.
 
{{New feature/item|3.0132|1.3.2||
If the element is a player, this function will use the players voice.
}}
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">float getSoundLength ( element theSound )</syntaxhighlight>  
<syntaxhighlight lang="lua">float getSoundLength ( element theSound )</syntaxhighlight>  
 
{{OOP||[[sound]]:getLength|length}}
===Required Arguments===  
===Required Arguments===  
*'''theSound:''' The [[sound]] element which length you want to return.
*'''theSound:''' the [[sound]] element which length you want to return.


===Returns===
===Returns===
Line 15: Line 17:
Plays a sound then outputs the sound length.
Plays a sound then outputs the sound length.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local sound = playSound("money.mp3",false) --Play a sound
local sound = playSound("money.mp3", false) -- Play a sound
local soundLength = getSoundLength(sound) --Get the length of the sound
local soundLength = getSoundLength(sound) -- Get the length of the sound
outputChatBox("This sound is :" ..soundLength.. " long!")
outputChatBox("This sound is " .. soundLength .. " seconds long.")
</syntaxhighlight>
</syntaxhighlight>
==Changelog==
{{ChangelogHeader}}
{{ChangelogItem|1.3.2|Added player element to use a players voice}}


==See Also==
==See Also==
{{Client_audio_functions}}
{{Client_audio_functions}}
[[hu:getSoundLength]]
[[ar:getSoundLength]]
[[ro:getSoundLength]]
[[pt-br:getSoundLength]]

Latest revision as of 16:36, 26 September 2021

This function is used to return the playback length of the specified sound element. If the element is a player, this function will use the players voice.

Syntax

float getSoundLength ( element theSound )

OOP Syntax Help! I don't understand this!

Method: sound:getLength(...)
Variable: .length


Required Arguments

  • theSound: the sound element which length you want to return.

Returns

Returns an float value indicating the playback length of the sound element in seconds.

Example

Plays a sound then outputs the sound length.

local sound = playSound("money.mp3", false) -- Play a sound
local soundLength = getSoundLength(sound) -- Get the length of the sound
outputChatBox("This sound is " .. soundLength .. " seconds long.")

Changelog

Version Description
1.3.2 Added player element to use a players voice

See Also