Repository navigation
Fix AudioPlayer disposal reentrancy - #218
Merged
Merged
Conversation
Prevent disposal and source replacement from raising PlaybackEnded while native resources are being torn down. Mark players disposed before cleanup and ignore queued native completion callbacks on Windows and Apple platforms. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 56d5ce10-8e4c-4df1-9c08-b4596ebb6c10
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a Windows stack overflow scenario caused by AudioPlayer.Dispose() re-entering PlaybackEnded during teardown, by preventing disposal and source-replacement cleanup from emitting PlaybackEnded while native resources are being released. The change aligns Windows and iOS/macOS behavior by separating “explicit Stop notification” from “silent cleanup” paths and by ignoring completion callbacks after disposal begins.
Changes:
- Windows: suppresses
PlaybackEndedreentrancy by short-circuiting completion callbacks once disposal starts and by using a non-notifying stop duringDispose. - iOS/macOS: mirrors the same pattern by adding a non-notifying stop path for disposal/source replacement and ignoring finished-playing callbacks once disposed.
- Preserves public
Stop()behavior by routing it through a notifying stop path, while internal cleanup uses a non-notifying variant.
Show a summary per file
| File | Description |
|---|---|
| src/Plugin.Maui.Audio/AudioPlayer/AudioPlayer.windows.cs | Adds isDisposed guard to completion callback and introduces Stop(bool raisePlaybackEnded) to avoid raising PlaybackEnded during disposal. |
| src/Plugin.Maui.Audio/AudioPlayer/AudioPlayer.macios.cs | Introduces non-notifying stop for disposal/source replacement, marks disposed earlier, and ignores FinishedPlaying callbacks once disposed. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
Contributor
There was a problem hiding this comment.
Review details
Suppressed comments (1)
src/Plugin.Maui.Audio/AudioPlayer/AudioPlayer.windows.cs:159
PlaybackEndedis raised with the nativeMediaPlayeras the event sender on Windows (sender), but other platform implementations raise it with theAudioPlayerinstance (this). This makes the event sender inconsistent across platforms and can break consumers that treatsenderasIAudioPlayer. Consider raising withthishere and ignoring the native sender parameter.
PlaybackEnded?.Invoke(sender, EventArgs.Empty);
}
- Files reviewed: 1/1 changed files
- Comments generated: 0 new
- Review effort level: Lite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Hardens the Windows
AudioPlayercompletion/disposal path so disposing fromPlaybackEndedcannot recurse or deliver a queued completion after disposal.Stop()behavior unchanged: it still raisesPlaybackEnded.Fixes #214.
A dedicated regression test is not included because the repository has no test project and this behavior depends on native
MediaPlayercallbacks. The Windows plugin/sample CI builds and generated NuGet artifact provide the practical validation path.Platforms Affected
Breaking Changes
None.
Checklist