From b255e9f1a303830e4bb8b0a53a89fb5f4818087c Mon Sep 17 00:00:00 2001 From: Stephen Booth Date: Sat, 28 Mar 2026 09:30:41 -0500 Subject: [PATCH 1/4] Add `BOOL` return to `audioPlayerEndOfAudio:` delegate method --- Sources/CSFBAudioEngine/Player/AudioPlayer.mm | 8 ++++++-- .../include/SFBAudioEngine/SFBAudioPlayer.h | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Sources/CSFBAudioEngine/Player/AudioPlayer.mm b/Sources/CSFBAudioEngine/Player/AudioPlayer.mm index d90ecc09..63b81378 100644 --- a/Sources/CSFBAudioEngine/Player/AudioPlayer.mm +++ b/Sources/CSFBAudioEngine/Player/AudioPlayer.mm @@ -2100,9 +2100,13 @@ Flags clearFlags(Flags flags, std::memory_order order = std::memory_order_acq_re that->setNowPlaying(nil); + auto shouldStop = true; + if ([player.delegate respondsToSelector:@selector(audioPlayerEndOfAudio:)]) { - [player.delegate audioPlayerEndOfAudio:player]; - } else { + shouldStop = [player.delegate audioPlayerEndOfAudio:player]; + } + + if (shouldStop) { const auto didStopEngine = stopEngineIfRunning(); if (didStopEngine && [player.delegate respondsToSelector:@selector(audioPlayer:playbackStateChanged:)]) { diff --git a/Sources/CSFBAudioEngine/include/SFBAudioEngine/SFBAudioPlayer.h b/Sources/CSFBAudioEngine/include/SFBAudioEngine/SFBAudioPlayer.h index 5aab4c9e..f23c0316 100644 --- a/Sources/CSFBAudioEngine/include/SFBAudioEngine/SFBAudioPlayer.h +++ b/Sources/CSFBAudioEngine/include/SFBAudioEngine/SFBAudioPlayer.h @@ -366,7 +366,8 @@ NS_SWIFT_NAME(AudioPlayer.Delegate) - (void)audioPlayer:(SFBAudioPlayer *)audioPlayer playbackStateChanged:(SFBAudioPlayerPlaybackState)playbackState; /// Called to notify the delegate when rendering is complete for all available decoders /// - parameter audioPlayer: The `SFBAudioPlayer` object -- (void)audioPlayerEndOfAudio:(SFBAudioPlayer *)audioPlayer NS_SWIFT_NAME(audioPlayerEndOfAudio(_:)); +/// - returns: `YES` if the player should stop playback, `NO` to continue rendering silence +- (BOOL)audioPlayerEndOfAudio:(SFBAudioPlayer *)audioPlayer NS_SWIFT_NAME(audioPlayerEndOfAudio(_:)); /// Called to notify the delegate that the decoding and rendering processes for a decoder have been canceled by a /// user-initiated request /// - warning: Do not change any properties of `decoder` From 461982bbe70054e9e88a35208d7aec0c2ee027b1 Mon Sep 17 00:00:00 2001 From: Stephen Booth Date: Sat, 28 Mar 2026 09:33:01 -0500 Subject: [PATCH 2/4] Remove newline --- Sources/CSFBAudioEngine/Player/AudioPlayer.mm | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/CSFBAudioEngine/Player/AudioPlayer.mm b/Sources/CSFBAudioEngine/Player/AudioPlayer.mm index 63b81378..b111f464 100644 --- a/Sources/CSFBAudioEngine/Player/AudioPlayer.mm +++ b/Sources/CSFBAudioEngine/Player/AudioPlayer.mm @@ -2099,7 +2099,6 @@ Flags clearFlags(Flags flags, std::memory_order order = std::memory_order_acq_re #endif /* DEBUG */ that->setNowPlaying(nil); - auto shouldStop = true; if ([player.delegate respondsToSelector:@selector(audioPlayerEndOfAudio:)]) { From 2d3f502d71e796d772646221f231238849897427 Mon Sep 17 00:00:00 2001 From: Stephen Booth Date: Mon, 30 Mar 2026 10:53:00 -0500 Subject: [PATCH 3/4] Rename delegate method --- Sources/CSFBAudioEngine/Player/AudioPlayer.mm | 4 ++-- .../CSFBAudioEngine/include/SFBAudioEngine/SFBAudioPlayer.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/CSFBAudioEngine/Player/AudioPlayer.mm b/Sources/CSFBAudioEngine/Player/AudioPlayer.mm index b111f464..b4851892 100644 --- a/Sources/CSFBAudioEngine/Player/AudioPlayer.mm +++ b/Sources/CSFBAudioEngine/Player/AudioPlayer.mm @@ -2101,8 +2101,8 @@ Flags clearFlags(Flags flags, std::memory_order order = std::memory_order_acq_re that->setNowPlaying(nil); auto shouldStop = true; - if ([player.delegate respondsToSelector:@selector(audioPlayerEndOfAudio:)]) { - shouldStop = [player.delegate audioPlayerEndOfAudio:player]; + if ([player.delegate respondsToSelector:@selector(audioPlayerShouldStopAtEndOfAudio:)]) { + shouldStop = [player.delegate audioPlayerShouldStopAtEndOfAudio:player]; } if (shouldStop) { diff --git a/Sources/CSFBAudioEngine/include/SFBAudioEngine/SFBAudioPlayer.h b/Sources/CSFBAudioEngine/include/SFBAudioEngine/SFBAudioPlayer.h index f23c0316..1976cf8f 100644 --- a/Sources/CSFBAudioEngine/include/SFBAudioEngine/SFBAudioPlayer.h +++ b/Sources/CSFBAudioEngine/include/SFBAudioEngine/SFBAudioPlayer.h @@ -364,10 +364,10 @@ NS_SWIFT_NAME(AudioPlayer.Delegate) /// - parameter audioPlayer: The `SFBAudioPlayer` object /// - parameter playbackState: The current playback state - (void)audioPlayer:(SFBAudioPlayer *)audioPlayer playbackStateChanged:(SFBAudioPlayerPlaybackState)playbackState; -/// Called to notify the delegate when rendering is complete for all available decoders +/// 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)audioPlayerEndOfAudio:(SFBAudioPlayer *)audioPlayer NS_SWIFT_NAME(audioPlayerEndOfAudio(_:)); +- (BOOL)audioPlayerShouldStopAtEndOfAudio:(SFBAudioPlayer *)audioPlayer NS_SWIFT_NAME(audioPlayerShouldStopAtEndOfAudio(_:)); /// Called to notify the delegate that the decoding and rendering processes for a decoder have been canceled by a /// user-initiated request /// - warning: Do not change any properties of `decoder` From daedc38047b25f02ba9c5e594185b614cf86ee69 Mon Sep 17 00:00:00 2001 From: Stephen Booth Date: Mon, 30 Mar 2026 10:56:30 -0500 Subject: [PATCH 4/4] Format code --- .../CSFBAudioEngine/include/SFBAudioEngine/SFBAudioPlayer.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/CSFBAudioEngine/include/SFBAudioEngine/SFBAudioPlayer.h b/Sources/CSFBAudioEngine/include/SFBAudioEngine/SFBAudioPlayer.h index 1976cf8f..0105323e 100644 --- a/Sources/CSFBAudioEngine/include/SFBAudioEngine/SFBAudioPlayer.h +++ b/Sources/CSFBAudioEngine/include/SFBAudioEngine/SFBAudioPlayer.h @@ -367,7 +367,8 @@ NS_SWIFT_NAME(AudioPlayer.Delegate) /// 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(_:)); +- (BOOL)audioPlayerShouldStopAtEndOfAudio:(SFBAudioPlayer *)audioPlayer + NS_SWIFT_NAME(audioPlayerShouldStopAtEndOfAudio(_:)); /// Called to notify the delegate that the decoding and rendering processes for a decoder have been canceled by a /// user-initiated request /// - warning: Do not change any properties of `decoder`