Skip to content

Commit

Permalink
refs #1663
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo4405 committed Jan 10, 2025
1 parent f246124 commit 3476494
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions HaishinKit/Sources/Mixer/MediaMixer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public final actor MediaMixer {

public private(set) var isRunning = false
private var outputs: [any MediaMixerOutput] = []
@MainActor
private var cancellables: Set<AnyCancellable> = []
private let useManualCapture: Bool
private lazy var audioIO = AudioCaptureUnit(session)
Expand Down Expand Up @@ -473,22 +474,24 @@ extension MediaMixer: AsyncRunner {
session.startRunning()
}
#if os(iOS) || os(tvOS) || os(visionOS)
NotificationCenter
.Publisher(center: .default, name: UIApplication.didEnterBackgroundNotification, object: nil)
.sink { _ in
Task { @MainActor in
await self.setBackgroundMode(true)
Task { @MainActor in
NotificationCenter
.Publisher(center: .default, name: UIApplication.didEnterBackgroundNotification, object: nil)
.sink { _ in
Task {
await self.setBackgroundMode(true)
}
}
}
.store(in: &cancellables)
NotificationCenter
.Publisher(center: .default, name: UIApplication.willEnterForegroundNotification, object: nil)
.sink { _ in
Task { @MainActor in
await self.setBackgroundMode(false)
.store(in: &cancellables)
NotificationCenter
.Publisher(center: .default, name: UIApplication.willEnterForegroundNotification, object: nil)
.sink { _ in
Task {
await self.setBackgroundMode(false)
}
}
}
.store(in: &cancellables)
.store(in: &cancellables)
}
#endif
}

Expand All @@ -502,8 +505,10 @@ extension MediaMixer: AsyncRunner {
}
audioIO.finish()
videoIO.finish()
cancellables.forEach { $0.cancel() }
cancellables.removeAll()
Task { @MainActor in
cancellables.forEach { $0.cancel() }
cancellables.removeAll()
}
Task { @ScreenActor in
displayLink.stopRunning()
}
Expand Down

0 comments on commit 3476494

Please sign in to comment.