SetSoundPosition: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Update remote audio file description "fix")
 
(12 intermediate revisions by 10 users not shown)
Line 2: Line 2:
{{Client function}}
{{Client function}}
This function is used to change the seek position of the specified [[sound]] element.
This function is used to change the seek position of the specified [[sound]] element.
{{New_feature|3.0139|1.3.2|
Use a player element to control a players voice with this function.
Use a player element to control a players voice with this function.
}}
 
{{Note|
*To set position of a remote audio file, you must pause the sound within an [[onClientSoundStream]] event after creation, set the sound position and then unpause it again. The sound can also not be throttled (see [[playSound]] arguments)}}
 
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">bool setSoundPosition ( element theSound, int pos )</syntaxhighlight>  
<syntaxhighlight lang="lua">bool setSoundPosition ( element theSound, float pos )</syntaxhighlight>  
 
{{OOP||[[sound]]:setPlaybackPosition|playbackPosition|getSoundPosition}}
===Required Arguments===  
===Required Arguments===  
*'''theSound:''' The [[sound]] element which seek position you want to modify.
*'''theSound:''' the [[sound]] element which seek position you want to modify.
*'''pos:''' An [[int]]eger value representing the new seek position of the sound in milliseconds.
*'''pos:''' a [[float]] value representing the new seek position of the [[sound]] element in seconds.


===Returns===
===Returns===
Line 17: Line 19:
==Example==  
==Example==  
This example allows the player to set how many milliseconds into the song he wants it to play from
This example allows the player to set how many milliseconds into the song he wants it to play from
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
theSound = playSound("music/song.mp3")
theSound = playSound("music/song.mp3")
function setSongPos(cmd, ms)
function setSongPos(cmd, tm)
     local ssp = setSoundPosition(theSound, ms)
    tm = tonumber(tm)
     local ssp = setSoundPosition(theSound,tm)
     if ssp then
     if ssp then
        local seconds = ms / 1000 --this will get the amount of seconds from milliseconds
         outputChatBox("Sound is now playing from: "..tostring(tm))
         outputChatBox("Sound is now playing from: "..seconds.." Seconds!")
     else
     else
         outputChatBox("An error has occured. Please make shore there are atleast")
         outputChatBox("An error has occured.")
        local seconds = ms / 1000 --this will get the amount of seconds from milliseconds
        outputChatBox(seconds.." Seconds in this song!")
     end
     end
end
end
addCommandHandler("skipsong", setSongPos)
addCommandHandler("skipsong", setSongPos)
</syntaxhighlight>
</syntaxhighlight>
</section>


==Changelog==
==Changelog==
Line 41: Line 39:
==See Also==
==See Also==
{{Client_audio_functions}}
{{Client_audio_functions}}
[[AR:setSoundPosition]]
 
[[hu:setSoundPosition]]
[[ar:setSoundPosition]]
[[ro:setSoundPosition]]

Latest revision as of 02:30, 29 August 2021

This function is used to change the seek position of the specified sound element. Use a player element to control a players voice with this function.

[[{{{image}}}|link=|]] Note:
  • To set position of a remote audio file, you must pause the sound within an onClientSoundStream event after creation, set the sound position and then unpause it again. The sound can also not be throttled (see playSound arguments)

Syntax

bool setSoundPosition ( element theSound, float pos )

OOP Syntax Help! I don't understand this!

Method: sound:setPlaybackPosition(...)
Variable: .playbackPosition
Counterpart: getSoundPosition


Required Arguments

  • theSound: the sound element which seek position you want to modify.
  • pos: a float value representing the new seek position of the sound element in seconds.

Returns

Returns true if the sound element's seek position was successfully changed, false otherwise.

Example

This example allows the player to set how many milliseconds into the song he wants it to play from

theSound = playSound("music/song.mp3")
function setSongPos(cmd, tm)
    tm = tonumber(tm)
    local ssp = setSoundPosition(theSound,tm)
    if ssp then
        outputChatBox("Sound is now playing from: "..tostring(tm))
    else
        outputChatBox("An error has occured.")
    end
end
addCommandHandler("skipsong", setSongPos)

Changelog

Version Description
1.3.2 Added player element for voice control

See Also