@@ -144,12 +144,27 @@ internal class PlayerCoordinator: NSObject, PlayerDelegateProtocol {
144
144
#if os(iOS)
145
145
extension PlayerCoordinator : AVPictureInPictureControllerDelegate {
146
146
147
+ /// Called when Picture-in-Picture (PiP) mode starts.
148
+ ///
149
+ /// - Parameter pictureInPictureController: The `AVPictureInPictureController` instance managing the PiP session.
150
+ ///
151
+ /// This method is marked as `nonisolated` to avoid being tied to the actor's execution context,
152
+ /// allowing it to be called from any thread. It publishes a `.startedPiP` event on the `eventPublisher`
153
+ /// within a `Task` running on the `MainActor`, ensuring UI updates are handled on the main thread.
147
154
nonisolated func pictureInPictureControllerDidStartPictureInPicture( _ pictureInPictureController: AVPictureInPictureController ) {
148
155
Task { @MainActor in
149
156
eventPublisher. send ( . startedPiP)
150
157
}
151
158
}
152
159
160
+
161
+ /// Called when Picture-in-Picture (PiP) mode stops.
162
+ ///
163
+ /// - Parameter pictureInPictureController: The `AVPictureInPictureController` instance managing the PiP session.
164
+ ///
165
+ /// Like its counterpart for starting PiP, this method is `nonisolated`, allowing it to be executed from any thread.
166
+ /// It sends a `.stoppedPiP` event via `eventPublisher` on the `MainActor`, ensuring any UI-related handling
167
+ /// occurs safely on the main thread.
153
168
nonisolated func pictureInPictureControllerDidStopPictureInPicture( _ pictureInPictureController: AVPictureInPictureController ) {
154
169
Task { @MainActor in
155
170
eventPublisher. send ( . stoppedPiP)
0 commit comments