|
|
|
@ -33,13 +33,29 @@ public class OWSAudioSession: NSObject {
|
|
|
|
|
|
|
|
|
|
private var currentActivities: [Weak<AudioActivity>] = []
|
|
|
|
|
|
|
|
|
|
// Ignores hardware mute switch, plays through external speaker
|
|
|
|
|
public func setPlaybackCategory(audioActivity: AudioActivity) {
|
|
|
|
|
// Respects hardware mute switch, plays through external speaker, mixes with backround audio
|
|
|
|
|
// appropriate for foreground sound effects.
|
|
|
|
|
public func startAmbientAudioActivity(_ audioActivity: AudioActivity) {
|
|
|
|
|
Logger.debug("\(logTag) in \(#function)")
|
|
|
|
|
|
|
|
|
|
// In general, we should have put the audio session back to it's default
|
|
|
|
|
// category when we were done with whatever activity required it to be modified
|
|
|
|
|
assert(avAudioSession.category == AVAudioSessionCategorySoloAmbient)
|
|
|
|
|
startAudioActivity(audioActivity)
|
|
|
|
|
|
|
|
|
|
guard currentActivities.count == 0 else {
|
|
|
|
|
// We don't want to clobber the audio capabilities configured by (e.g.) media playback or an in-progress call
|
|
|
|
|
Logger.info("\(logTag) in \(#function) not touching audio session since another currentActivity exists.")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
try avAudioSession.setCategory(AVAudioSessionCategoryAmbient)
|
|
|
|
|
} catch {
|
|
|
|
|
owsFail("\(logTag) in \(#function) failed with error: \(error)")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ignores hardware mute switch, plays through external speaker
|
|
|
|
|
public func startPlaybackAudioActivity(_ audioActivity: AudioActivity) {
|
|
|
|
|
Logger.debug("\(logTag) in \(#function)")
|
|
|
|
|
|
|
|
|
|
startAudioActivity(audioActivity)
|
|
|
|
|
|
|
|
|
@ -50,13 +66,9 @@ public class OWSAudioSession: NSObject {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public func setRecordCategory(audioActivity: AudioActivity) -> Bool {
|
|
|
|
|
public func startRecordingAudioActivity(_ audioActivity: AudioActivity) -> Bool {
|
|
|
|
|
Logger.debug("\(logTag) in \(#function)")
|
|
|
|
|
|
|
|
|
|
// In general, we should have put the audio session back to it's default
|
|
|
|
|
// category when we were done with whatever activity required it to be modified
|
|
|
|
|
assert(avAudioSession.category == AVAudioSessionCategorySoloAmbient)
|
|
|
|
|
|
|
|
|
|
assert(avAudioSession.recordPermission() == .granted)
|
|
|
|
|
|
|
|
|
|
startAudioActivity(audioActivity)
|
|
|
|
@ -104,8 +116,6 @@ public class OWSAudioSession: NSObject {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
try avAudioSession.setCategory(AVAudioSessionCategorySoloAmbient)
|
|
|
|
|
|
|
|
|
|
// When playing audio in Signal, other apps audio (e.g. Music) is paused.
|
|
|
|
|
// By notifying when we deactivate, the other app can resume playback.
|
|
|
|
|
try avAudioSession.setActive(false, with: [.notifyOthersOnDeactivation])
|
|
|
|
|