Skip to content

Play audio sources from a start with an optional fade-in, and report a buffer's duration - #731

Merged
stanoddly merged 1 commit into
mainfrom
audio-play-start
Nov 19, 2026
Merged

stanoddly merged 1 commit into
mainfrom
audio-play-start

Conversation

@botoddly

Copy link
Copy Markdown
Collaborator

Fixes #730

  • AudioBuffer.Duration is a TimeSpan? from MIX_GetAudioDuration, rounded down to whole milliseconds. It is null for a sound that loops forever, such as a WAV loop whose play count is zero or an OGG LOOPSTART tag without a count: SDL_mixer reports MIX_DURATION_INFINITE for these. A stream has no duration, because SDL_mixer hides the audio it creates in MIX_SetTrackIOStream.
  • AudioSource.Play(TimeSpan start) and Play(TimeSpan start, TimeSpan fadeIn) pass MIX_PROP_PLAY_START_MILLISECOND_NUMBER and MIX_PROP_PLAY_FADE_IN_MILLISECONDS_NUMBER to MIX_PlayTrack. Play() calls them with zero for both. A looping clip loops back to its beginning.
  • A negative start or fade-in throws ArgumentOutOfRangeException, and so does a start after the end of a buffer. SDL_mixer's seek past the end of a buffer fails without setting an error, so Pixely checks this itself. A start the decoder cannot seek to throws PixelyException. Two examples: a start past the file's length in a WAV that loops forever, and a non-zero start in a stream whose content cannot seek.
  • Fixes Looping = true set before Play(), which never looped: MIX_PlayTrack resets the loop count, so the count now goes in its options.
  • StubAudioSystem reports a zero Duration and does not check a start against the end. This is documented in docs/testing.md.
  • New tests in AudioSystemTests play the last 50 ms of a buffer and of a stream and wait for them to stop. They also check that a looping source still plays after a one-shot source with the same start has stopped, and they cover a WAV with an endless smpl loop.

…ffer's duration, and keep Looping set before Play
@stanoddly
stanoddly merged commit 95f5ab1 into main Nov 19, 2026
3 checks passed
@stanoddly
stanoddly deleted the audio-play-start branch November 19, 2026 14:25
@github-actions

Copy link
Copy Markdown

📦 Development package Pixely 0.0.177 is available.

Workflow run (attempt 1)

@github-actions

Copy link
Copy Markdown

✅ Development package validation passed on all platforms.

Workflow run (attempt 1)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AudioSource can't start a clip partway through, or fade it in

2 participants