Skip to content

Commit

Permalink
Small AudioEngine update.
Browse files Browse the repository at this point in the history
  • Loading branch information
v-grigoriev committed Apr 15, 2021
1 parent aeae764 commit f9e94ee
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- SCNRecorder (2.5.0)
- SCNRecorder (2.5.1)
- SnapKit (5.0.1)

DEPENDENCIES:
Expand All @@ -15,7 +15,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
SCNRecorder: 87469846988b24e3b9f28aa501e2133f5edd6d7b
SCNRecorder: b446114276ca77d0b247836b28c3b9ae80b2cb08
SnapKit: 97b92857e3df3a0c71833cce143274bf6ef8e5eb

PODFILE CHECKSUM: a402c811b8b6a231a13402257d93acd3b67abb0d
Expand Down
4 changes: 2 additions & 2 deletions Example/Pods/Local Podspecs/SCNRecorder.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion SCNRecorder.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'SCNRecorder'
s.version = '2.5.0'
s.version = '2.5.1'
s.summary = 'A lags-free recorder of ARKit and SceneKit for iOS in Swift'
s.homepage = 'https://github.com/gorastudio/SCNRecorder'
s.license = { :type => 'MIT', :file => 'LICENSE.md' }
Expand Down
4 changes: 2 additions & 2 deletions SCNRecorder.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 2.5.0;
MARKETING_VERSION = 2.5.1;
MODULEMAP_FILE = SCNRecorder.modulemap;
PRODUCT_BUNDLE_IDENTIFIER = gora.studio.SCNRecorder;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
Expand Down Expand Up @@ -1066,7 +1066,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 2.5.0;
MARKETING_VERSION = 2.5.1;
MODULEMAP_FILE = SCNRecorder.modulemap;
PRODUCT_BUNDLE_IDENTIFIER = gora.studio.SCNRecorder;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
Expand Down
22 changes: 10 additions & 12 deletions Sources/AudioEngine/AudioEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public final class AudioEngine {
guard !isInterrupted else { return false }

do {
try self.activateAudioSessionIfNeeded()
try self.activateAudioSession()
try self.engine.start()
return true
}
Expand All @@ -108,15 +108,15 @@ public final class AudioEngine {
player.didPause = { [weak self] in
guard let self = self else { return }
self.engine.pause()
self.deactivateAudioSessionIfNeeded()
self.deactivateAudioSession()
}

player.didStop = { [weak self] in
guard let self = self else { return }

self.engine.stop()
self.engine.reset()
self.deactivateAudioSessionIfNeeded()
self.deactivateAudioSession()
}
}
}
Expand Down Expand Up @@ -154,31 +154,29 @@ public final class AudioEngine {
}
}

let exclusivelyManageAudioSession: Bool
let canDeactivateAudioSession: Bool

@Observable public internal(set) var error: Swift.Error?

public init(exclusivelyManageAudioSession: Bool = true) {
self.exclusivelyManageAudioSession = exclusivelyManageAudioSession
public init(canDeactivateAudioSession: Bool = true) {
self.canDeactivateAudioSession = canDeactivateAudioSession
setupObservers()
}

deinit {
recorder?.audioInput.audioFormat = nil
player?.stop()
observers.forEach { notificationCenter.removeObserver($0) }
deactivateAudioSessionIfNeeded()
deactivateAudioSession()
}

func activateAudioSessionIfNeeded() throws {
guard exclusivelyManageAudioSession else { return }

func activateAudioSession() throws {
try audioSession.setCategory(.playAndRecord, options: .defaultToSpeaker)
try audioSession.setActive(true)
}

func deactivateAudioSessionIfNeeded() {
guard exclusivelyManageAudioSession else { return }
func deactivateAudioSession() {
guard canDeactivateAudioSession else { return }

do { try audioSession.setActive(false) }
catch { self.error = error }
Expand Down

0 comments on commit f9e94ee

Please sign in to comment.