Skip to content

Conversation

@ThereDrD0
Copy link
Contributor

@ThereDrD0 ThereDrD0 commented Dec 4, 2025

I encountered an odd bug: if I go far away from a looped audio source and return, the audio stops playing on the client. Disconnecting and reconnecting restores playback.

I figured out that it was a bug with the playback position calculation. It didn't account for the Loop parameter correctly and stopped playing because the position exceeded the audio length.

Here is a fix. + clean up redundant code and unused usings

Tests

image

Example

Before(master)

2025-12-24.22-13-05.mp4

After(my branch)

2025-12-24.22-09-49.mp4

Example code used to reproduce bug

using Robust.Server.Audio;

namespace Content.Server.AAA;

public sealed class TestSoundSystem : EntitySystem
{
    [Dependency] private readonly AudioSystem _audio = default!;

    public override void Initialize()
    {
        base.Initialize();

        SubscribeLocalEvent<TestSoundComponent, MapInitEvent>(OnMapInit);
    }

    private void OnMapInit(Entity<TestSoundComponent> ent, ref MapInitEvent args)
    {
        _audio.PlayPvs(ent.Comp.Sound, ent);
    }
}
using Robust.Shared.Audio;

namespace Content.Server.AAA;

[RegisterComponent]
public sealed partial class TestSoundComponent : Component
{
    [DataField]
    public SoundSpecifier Sound = new SoundPathSpecifier("/Audio/Effects/glass_break1.ogg",
        AudioParams.Default.WithMaxDistance(30f).WithVolume(10f).WithLoop(true));
}

Copy link
Member

@PJB3005 PJB3005 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not copy paste this code around everywhere

@PJB3005 PJB3005 added T: Bugfix Type: Bugs and/or bugfixes A: Audio Audio playback / recording labels Dec 4, 2025
@ThereDrD0 ThereDrD0 requested a review from PJB3005 December 6, 2025 03:19
@ThereDrD0
Copy link
Contributor Author

Hey, just wondering if this is good to go?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A: Audio Audio playback / recording T: Bugfix Type: Bugs and/or bugfixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants