Add audioPlayerShouldStopAtEndOfAudio: delegate method#897
Add audioPlayerShouldStopAtEndOfAudio: delegate method#897
audioPlayerShouldStopAtEndOfAudio: delegate method#897Conversation
There was a problem hiding this comment.
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 fromvoidtoBOOLand document the return value. - Update
AudioPlayerend-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.
| /// - returns: `YES` if the player should stop playback, `NO` to continue rendering silence | ||
| - (BOOL)audioPlayerEndOfAudio:(SFBAudioPlayer *)audioPlayer NS_SWIFT_NAME(audioPlayerEndOfAudio(_:)); |
There was a problem hiding this comment.
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.
| /// - 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(_:)); |
|
|
||
| if ([player.delegate respondsToSelector:@selector(audioPlayerEndOfAudio:)]) { | ||
| [player.delegate audioPlayerEndOfAudio:player]; | ||
| } else { | ||
| shouldStop = [player.delegate audioPlayerEndOfAudio:player]; | ||
| } | ||
|
|
There was a problem hiding this comment.
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.
BOOL return to audioPlayerEndOfAudio: delegate methodaudioPlayerShouldStopAtEndOfAudio: delegate method
There was a problem hiding this comment.
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.
This is a breaking API change since this PR removes the
audioPlayerEndOfAudio:delegate method.