Xogy / xsound

Improved audio library for FiveM
MIT License
115 stars 82 forks source link

[request] Multiple positions - [bug] yPlayer.seekTo #41

Closed SNXdevelopment closed 1 year ago

SNXdevelopment commented 1 year ago

[feature request]

I wanted to make multiple "speaker" positions in one club for a better feeling. The only problem now is, that when i create 4 different positions and play the same music on all, every position is delayed a bit more.

It would be nice if its possible to create multiple positions in one "name" for the music to be played. In that way instead of just one position, you could directly update the whole "name"-group with a new song for example. Maybe take a table with vec3's instead of one simple vec3 in the PlayUrlPos export. The music could be played either on all positions simultaneously or one time in the middle of all with volume recalculated based on the distance to the near positions.

[bug]

If you try to set the timestamp to.. 10 seconds it will print that yPlayer.seekTo is not a function. Screenshot_3

and 3D-Sound doesnt seem to work either, i always hear the music on both sides.

It could be me beeing an idiot, or just some little bugs in the script. I tried the newest release aswell as the source, nothing.

Xogy commented 1 year ago

It might be just because the music wasn't ready yet you should use the event "onPlayStart" when trying to set a time stamp.

SNXdevelopment commented 1 year ago

First of all, ty for replying. I "reworked" it to wait for all boxes to load and afterwards set the timestamp of all to 0 with a loop. It kind of fixed it, but i recognized if you run between those boxes, they start delaying a bit again.

just for the sake of safety here is the codepart

local systems = {}
RegisterNetEvent('snxMedia:cl:soundHandler')
AddEventHandler('snxMedia:cl:soundHandler', function(type, data, link)
    if type == 'play' then

        -- create system
        local boxes = {}
        for k, v in pairs(data) do table.insert(boxes, {boxId=k, position=v}) end
        table.insert(systems, #systems+1, {boxes=boxes, systemId=#systems+1})

        local bLoaded = {}
        for k, v in pairs(data) do
            xSound:PlayUrlPos(k, link, 1.0, v, false,{
                onPlayStart = function(event)
                    table.insert(bLoaded, {
                        Id = 1,
                        boxId = k
                    })
                end,
            })
        end

        --wait for all to be loaded and break if not loaded
        local sCounter, breakHandler = 0, false
        while (#bLoaded < #data) do
            sCounter = sCounter + 1
            if sCounter > 40 then breakHandler = true   end
            Wait(250)
        end
        if breakHandler then table.remove(systems, #systems) return end

        for i=1, #bLoaded do
            xSound:setTimeStamp(bLoaded[i].boxId, 0)
            print('set timestamp for '..bLoaded[i].boxId)
        end

    elseif type == 'stop' then
    elseif type == 'resume' then
    end
end)

Would be awesome if you could help out. If there arent any fixes for this method, i will try the other one with calculating distance and stuff.

Xogy commented 1 year ago
RegisterNetEvent('snxMedia:cl:soundHandler')
AddEventHandler('snxMedia:cl:soundHandler', function(type, data, link)
    if type == 'play' then
        local bLoaded = {}
        local dataCount = #data
        for k, v in pairs(data) do
            xSound:PlayUrlPos(k, link, 1.0, v, false,{
                onPlayStart = function(event)
                    dataCount = dataCount - 1
                    print(dataCount)
                end,
            })
        end

        while dataCount ~= 0 do
            Wait(33)
        end

        for k, v in pairs(data) do
            xSound:setTimeStamp(k, 0)
        end

    elseif type == 'stop' then
    elseif type == 'resume' then
    end
end)