Skip to content

Commit

Permalink
코드리뷰 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
ParkJongSang committed Oct 16, 2023
1 parent ebbd346 commit c0a93b5
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions NuguClientKit/Sources/Audio/AudioSessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ final public class AudioSessionManager: AudioSessionManageable {
// When no other audio is playing, audio session can not detect car play connectivity status even if car play has been already connected.
// To resolve this problem, activating audio session should be done in prior to detecting car play connectivity.
if AVAudioSession.sharedInstance().isOtherAudioPlaying == false {
try? activeAudioSessionIfNeeded(categoryOptions: defaultCategoryOptions)
try activeAudioSessionIfNeeded()
}
}

Expand Down Expand Up @@ -87,7 +87,8 @@ public extension AudioSessionManager {
AVAudioSession.sharedInstance().category != .playback ||
AVAudioSession.sharedInstance().categoryOptions != options else { return true }
do {
try activeAudioSessionIfNeeded(categoryOptions: options)
try setAudioCategoryIfNeeded(.playback, options: options)
try activeAudioSessionIfNeeded()
return true
} catch {
log.debug("updateAudioSessionToPlaybackIfNeeded failed: \(error)")
Expand All @@ -104,7 +105,8 @@ public extension AudioSessionManager {
return true
}
do {
try activeAudioSessionIfNeeded(categoryOptions: [])
try setAudioCategoryIfNeeded(.playAndRecord, options: [])
try activeAudioSessionIfNeeded()
return true
} catch {
log.debug("updateAudioSession when carplay connected has failed: \(error)")
Expand Down Expand Up @@ -137,7 +139,8 @@ public extension AudioSessionManager {
}

do {
try activeAudioSessionIfNeeded(categoryOptions: options)
try setAudioCategoryIfNeeded(.playAndRecord, options: options)
try activeAudioSessionIfNeeded()

return true
} catch {
Expand Down Expand Up @@ -258,20 +261,24 @@ private extension AudioSessionManager {
// MARK: - Private (audioSessiontActive)

private extension AudioSessionManager {
func activeAudioSessionIfNeeded(categoryOptions: AVAudioSession.CategoryOptions) throws {
func activeAudioSessionIfNeeded() throws {
guard delegate?.allowsUpdateAudioSessionActivation == true else { return }

try AVAudioSession.sharedInstance().setActive(true)

log.debug("audio session activated")
}

func setAudioCategoryIfNeeded(_ category: AVAudioSession.Category, options: AVAudioSession.CategoryOptions) throws {
guard delegate?.allowsUpdateAudioSessionActivation == true else { return }

try AVAudioSession.sharedInstance().setCategory(
.playback,
category,
mode: .default,
options: categoryOptions
)

log.debug("set audio session: \(AVAudioSession.Category.playAndRecord), options: \(categoryOptions)")

try AVAudioSession.sharedInstance().setActive(true)

log.debug("audio session activated")
log.debug("set audio session: \(category), options: \(options)")
}
}

Expand Down

0 comments on commit c0a93b5

Please sign in to comment.