Skip to content

Commit fff5ed9

Browse files
authored
Merge pull request #42 from jpsim/fix-tuner-becoming-frozen-when-resuming-from-background
Fix tuner becoming frozen when resuming from background
2 parents e75288d + 2e72b4e commit fff5ed9

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.2.2
2+
3+
* Fixed an issue where the tuner would become unresponsive after
4+
switching to other apps.
5+
16
## 0.2.1
27

38
* The app no longer dims the display after a period of inactivity on

Packages/MicrophonePitchDetector/Sources/MicrophonePitchDetector/AudioEngine.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ extension AVAudioMixerNode {
5959
final class AudioEngine {
6060
/// Internal AVAudioEngine
6161
private let avEngine = AVAudioEngine()
62+
private let session = AVAudioSession.sharedInstance()
6263

6364
/// Main mixer at the end of the signal chain
6465
private var mainMixerNode: Mixer?
@@ -91,11 +92,14 @@ final class AudioEngine {
9192
/// Start the engine
9293
func start() throws {
9394
try avEngine.start()
95+
try session.setCategory(.playAndRecord, options: [.defaultToSpeaker, .mixWithOthers])
96+
try session.setActive(true)
9497
}
9598

9699
/// Stop the engine
97-
func stop() {
100+
func stop() throws {
98101
avEngine.stop()
102+
try session.setActive(false)
99103
}
100104

101105
// MARK: - Private

Packages/MicrophonePitchDetector/Sources/MicrophonePitchDetector/MicrophonePitchDetector.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ public final class MicrophonePitchDetector: ObservableObject {
2828

2929
public func stop() {
3030
guard hasMicrophoneAccess else { return }
31-
engine.stop()
31+
do {
32+
try engine.stop()
33+
} catch {
34+
// TODO: Handle error
35+
}
3236
}
3337

3438
// MARK: - Private

0 commit comments

Comments
 (0)