Skip to content

Add audioPlayerShouldStopAtEndOfAudio: delegate method#897

Open
sbooth wants to merge 7 commits intomainfrom
endofaudio
Open

Add audioPlayerShouldStopAtEndOfAudio: delegate method#897
sbooth wants to merge 7 commits intomainfrom
endofaudio

Conversation

@sbooth
Copy link
Copy Markdown
Owner

@sbooth sbooth commented Mar 28, 2026

This is a breaking API change since this PR removes the audioPlayerEndOfAudio: delegate method.

Copilot AI review requested due to automatic review settings March 28, 2026 14:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the SFBAudioPlayerDelegate end-of-audio callback to return a boolean so the delegate can decide whether playback should stop or the engine should continue rendering silence after all decoders are finished.

Changes:

  • Change audioPlayerEndOfAudio: delegate method signature from void to BOOL and document the return value.
  • Update AudioPlayer end-of-audio handling to stop the engine only when the delegate indicates it should.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
Sources/CSFBAudioEngine/include/SFBAudioEngine/SFBAudioPlayer.h Updates delegate API to return BOOL at end-of-audio and documents behavior.
Sources/CSFBAudioEngine/Player/AudioPlayer.mm Uses the delegate’s return value to decide whether to stop the engine after reaching end-of-audio.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +369 to +370
/// - returns: `YES` if the player should stop playback, `NO` to continue rendering silence
- (BOOL)audioPlayerEndOfAudio:(SFBAudioPlayer *)audioPlayer NS_SWIFT_NAME(audioPlayerEndOfAudio(_:));
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

Changing audioPlayerEndOfAudio: from void to BOOL is a source- and ABI-breaking API change for any downstream delegate implementations. Because the selector name is unchanged, any client compiled against the old signature could still respond to the selector at runtime but return an undefined value, causing the player to potentially not stop (or behave unpredictably). Consider adding a new delegate method with a distinct selector for the stop/continue decision (and keep the existing void callback for notification, possibly deprecated), or ensure this ships with an explicit major-version bump + migration guidance.

Suggested change
/// - returns: `YES` if the player should stop playback, `NO` to continue rendering silence
- (BOOL)audioPlayerEndOfAudio:(SFBAudioPlayer *)audioPlayer NS_SWIFT_NAME(audioPlayerEndOfAudio(_:));
- (void)audioPlayerEndOfAudio:(SFBAudioPlayer *)audioPlayer NS_SWIFT_NAME(audioPlayerEndOfAudio(_:));
/// Called to query the delegate whether playback should stop when rendering is complete for all available decoders
/// - parameter audioPlayer: The `SFBAudioPlayer` object
/// - returns: `YES` if the player should stop playback, `NO` to continue rendering silence
- (BOOL)audioPlayerShouldStopAtEndOfAudio:(SFBAudioPlayer *)audioPlayer NS_SWIFT_NAME(audioPlayerShouldStopAtEndOfAudio(_:));

Copilot uses AI. Check for mistakes.
Comment on lines 2103 to +2107

if ([player.delegate respondsToSelector:@selector(audioPlayerEndOfAudio:)]) {
[player.delegate audioPlayerEndOfAudio:player];
} else {
shouldStop = [player.delegate audioPlayerEndOfAudio:player];
}

Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

Because the selector audioPlayerEndOfAudio: is unchanged but the return type changed, a delegate built against the previous - (void)audioPlayerEndOfAudio: signature may still respond at runtime and this call will interpret an undefined return value as BOOL (often NO), leaving the engine running unexpectedly. If binary/runtime compatibility is a concern, prefer introducing a new selector for the shouldStop decision (and keep calling the legacy void callback), rather than changing the return type in-place.

Copilot uses AI. Check for mistakes.
@sbooth sbooth changed the title Add BOOL return to audioPlayerEndOfAudio: delegate method Add audioPlayerShouldStopAtEndOfAudio: delegate method Mar 30, 2026
Copy link
Copy Markdown

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Cpp-linter Review

Used clang-format v22.1.3

Click here for the full clang-format patch
diff --git a/Sources/CSFBAudioEngine/include/SFBAudioEngine/SFBAudioPlayer.h b/Sources/CSFBAudioEngine/include/SFBAudioEngine/SFBAudioPlayer.h
index 1976cf8..0105323 100644
--- a/Sources/CSFBAudioEngine/include/SFBAudioEngine/SFBAudioPlayer.h
+++ b/Sources/CSFBAudioEngine/include/SFBAudioEngine/SFBAudioPlayer.h
@@ -370 +370,2 @@ NS_SWIFT_NAME(AudioPlayer.Delegate)
-- (BOOL)audioPlayerShouldStopAtEndOfAudio:(SFBAudioPlayer *)audioPlayer NS_SWIFT_NAME(audioPlayerShouldStopAtEndOfAudio(_:));
+- (BOOL)audioPlayerShouldStopAtEndOfAudio:(SFBAudioPlayer *)audioPlayer
+        NS_SWIFT_NAME(audioPlayerShouldStopAtEndOfAudio(_:));

Have any feedback or feature suggestions? Share it here.

Comment thread Sources/CSFBAudioEngine/include/SFBAudioEngine/SFBAudioPlayer.h Outdated
@github-actions github-actions bot dismissed their stale review March 30, 2026 15:57

outdated suggestion

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.

2 participants