AudioPlayer playing should overlap

Recently started using the new Audio instances but I found out they don’t overlap and will NOT play until the current play session is over, this is very inconvenient since sounds have a slight delay before ending, making the next session not play at all, you were able to overlap play with PlayLocalSound but that doesn’t work with AudioPlayer, either add an option to play overlapping sounds or make PlayLocalSound work with AudioPlayer

Hey @weakroblox35 – Sound:Play() behaves slightly differently than AudioPlayer:Play(), Sound will rewind to the beginning (TimePosition = 0) before playing, whereas AudioPlayer:Play() behaves more like Sound:Resume(), picking up wherever the TimePosition currently is.

they don’t overlap and will NOT play until the current play session is over

If an AudioPlayer is already playing, calling :Play() again will do nothing, whereas Sound:Play() would rewind to the beginning. Neither API implements overlapped playback via its own properties and methods

SoundService:PlayLocalSound and Sound.PlayOnRemove are implemented by making a secret/internal copy of the sound, and playing that to completion.

In retrospect these APIs have been extraordinarily buggy – both suffer from inability to find the “detached” copies of a sound after it has started playing (since it’s nowhere to be found in the DataModel) – for fire-and-forget/oneshots, that’s probably ok, but their performance isn’t actually better than writing the same code in a script, so it’s not something we built directly into the new audio API.

You can implement the same behavior by writing a function along the lines of

local function playCopy(of : AudioPlayer)
    local copy = Instance.new("AudioPlayer")
    -- copy all wires
    for _, wire in of:GetConnectedWires("Output") do
        local w = Instance.new("Wire")
        w.SourceInstance = copy
        w.TargetInstance = wire.TargetInstance
        w.TargetName = wire.TargetName
        w.Parent = copy -- parent wires to the copy so that destroying the copy destroys the wires too
    end
    copy.Asset = of.Asset
    copy.Volume = of.Volume
    copy.PlaybackSpeed = math.max(of.PlaybackSpeed, 0.1) -- playbackspeed cannot be 0 or the copy would play forever
    -- copy.Looping = of.Looping -- cannot loop or the copy would play forever

    copy.Ended:Connect(function() 
        copy:Destroy()
    end)

    copy.Parent = workspace -- anywhere works
    copy:Play()
end

If you are worried about instance creation/destruction time, you could augment this method with a pool