|
|
|
@ -33,14 +33,24 @@ public class OWSAudioSession: NSObject {
|
|
|
|
|
|
|
|
|
|
private var currentActivities: [Weak<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)")
|
|
|
|
|
|
|
|
|
|
startAudioActivity(audioActivity)
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
try avAudioSession.setCategory(AVAudioSessionCategoryAmbient)
|
|
|
|
|
} catch {
|
|
|
|
|
owsFail("\(logTag) in \(#function) failed with error: \(error)")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ignores hardware mute switch, plays through external speaker
|
|
|
|
|
public func setPlaybackCategory(audioActivity: AudioActivity) {
|
|
|
|
|
public func startPlaybackAudioActivity(_ 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)
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
@ -50,13 +60,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 +110,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])
|
|
|
|
|