Skip to content
forked from Xogy/xsound

Improved audio library for FiveM

License

Notifications You must be signed in to change notification settings

Jerrys-C/xsound

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

80 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#Improved audio library for FiveM

Can work with API interact sound
Just make sure you take all sounds from interact
sound and move them to xsound/html/sounds

Thanks to
https://github.com/plunkettscott
for awesome api
https://github.com/plunkettscott/interact-sound

SoundSystem functions

1. Functions (client side)


Playing sound


  • PlayUrl(name, URL, volume, loop, options)
    Will play sound from URL (can be heard everywhere)
    argument loop and options are optional, doesn't have to be used.

  • PlayUrlPos(name, url, volume, Vector3 vec, loop, options)
    Will play sound from url at x,y,z location
    argument loop and options are optional, doesn't have to be used.

options list

  • onPlayStart
  • onPlayEnd
  • onLoading
  • onPlayPause
  • onPlayResume

Manipulation with sound


  • Position(name, Vector3 vec)
    Will update location of sound

  • Distance(name, newDistance)
    Will set new playing distance from location

  • Destroy(name)
    Will destroy sound

  • Pause(name)
    Will pause sound

  • Resume(name)
    Will resume sound

  • setVolume(name,volume) volume is from 0.0 to 1.0
    Will set a new value to volume. Should be used for non 3D sound

  • setVolumeMax(name,volume) volume is from 0.0 to 1.0
    will set new value to max volume. Should be used only for 3D sound

  • setTimeStamp(name, time) will set a new timestamp.

  • setSoundURL(name, url) will set new URL to sound (will play whenever changed)

  • repeatSound(name) will play again the saved sound

  • destroyOnFinish(name, bool) true = destroy on end / false = do not destroy on end

  • setSoundLoop(name, bool) will set a new value to loop

  • setSoundDynamic(name, bool) will set if the sound is 3D / 3D = true


Effects on sound


  • fadeOut(name, time)
  • fadeIn(name, time, volume)

Events (client side only)


  • onPlayStart(name, function)
    This event will trigger after the sound
    is loaded and start playing in game.

  • onPlayEnd(name, function)
    This event will be triggered after sound end.

  • onLoading(name, function)
    This event will be triggered when the sound start loading.

  • onPlayPause(name, function)
    This event will be triggered whenever you pause sound.

  • onPlayResume(name, function)
    This event will be triggered whenever you resume sound.


Getting info about sound


  • soundExists(name)
    Will return true/false if sound exists

  • isPaused(name)
    Will return true/false if song is paused

  • isPlaying(name)
    Will return true/false if song is playing

  • isLooped(name)
    Will return true/false if sound is looped

  • getDistance(name)
    Will return distance in Integer

  • getVolume(name)
    Will return current volume of music.

  • getPosition(name)
    Will return vector3

  • isDynamic(name)
    Will return if sound is 3D or 2D (3D = true, 2D = false)

  • getTimeStamp(name)
    returns current timestamp

  • getMaxDuration(name)
    returns max duration of sound

  • getLink(name)
    Will return url link

  • isPlayerInStreamerMode()
    will return if player got streamer mode enabled.

  • getAllAudioInfo()
    Will return array of all sound

  • isPlayerCloseToAnySound()
    will return true if player is close to any sound.

  • getInfo(name)
    Will return an array with info of the sound...

{
   volume,          -- value from 0.0 to 1.0
   url ,            -- sound url
   id,              -- id 
   position,        -- will be nil if position isnt set.
   distance,        -- distance in integer
   playing,         -- true/false
   paused,          -- true/false
   loop,            -- true/false
   isDynamic,       -- true/false
   timeStamp,       -- returns current timestamp
   maxDuration,     -- returns max duration of sound
   destroyOnFinish, -- default value is true means after its finish it will destroy it self
}

1. Functions (Server side)


Playing sound


  • PlayUrl(source, name, URL, volume, loop)
    Will play sound from URL (can be heard everywhere)

  • PlayUrlPos(source, name, url, volume, Vector3 vec, loop)
    Will play sound from url at x,y,z location


Manipulation with sound


  • -1 for source work as well

  • Position(source, name, Vector3 vec)
    Will update location of sound

  • Distance(source, name, newDistance)
    Will set new playing distance from location

  • Destroy(source, name)
    Will destroy sound

  • Pause(source, name)
    Will pause sound

  • Resume(source, name)
    Will resume sound

  • setVolume(source, name,volume) volume is from 0.0 to 1.0
    Will set a new value to volume. Should be used for non 3D sound

  • setVolumeMax(source, name,volume) volume is from 0.0 to 1.0
    will set new value to max volume. Should be used only for 3D sound

  • setTimeStamp(source ,name, time) will set a new timestamp.
    TIMESTAMP is in a seconds only !


Showcase how it can stream sound at game

https://www.youtube.com/watch?v=zyZmF5bRSA4

https://www.youtube.com/watch?v=19Q2GVYElSE

Showcase what I did with my API

#These are just a showcase! I will not share them....

https://www.youtube.com/watch?v=OOf6PZFpfkI

https://www.youtube.com/watch?v=JRTVga_FwGw

About

Improved audio library for FiveM

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua 59.6%
  • JavaScript 39.1%
  • HTML 1.3%