mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Temporary fix for audio delay
This commit is contained in:
parent
ee64afdf1a
commit
eac7b8d948
@ -19,7 +19,7 @@ public enum ManagedAudioSessionType: Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
private func nativeCategoryForType(_ type: ManagedAudioSessionType, headphones: Bool) -> AVAudioSession.Category {
|
||||
private func nativeCategoryForType(_ type: ManagedAudioSessionType, headphones: Bool, outputMode: AudioSessionOutputMode) -> AVAudioSession.Category {
|
||||
switch type {
|
||||
case .play:
|
||||
return .playback
|
||||
@ -29,7 +29,12 @@ private func nativeCategoryForType(_ type: ManagedAudioSessionType, headphones:
|
||||
if headphones {
|
||||
return .playback
|
||||
} else {
|
||||
switch outputMode {
|
||||
case .custom(.speaker), .system:
|
||||
return .playAndRecord
|
||||
default:
|
||||
return .playback
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -638,25 +643,29 @@ public final class ManagedAudioSession {
|
||||
self.currentTypeAndOutputMode = (type, outputMode)
|
||||
|
||||
do {
|
||||
print("ManagedAudioSession setting category for \(type)")
|
||||
let nativeCategory = nativeCategoryForType(type, headphones: self.isHeadsetPluggedInValue, outputMode: outputMode)
|
||||
|
||||
print("ManagedAudioSession setting category for \(type) (native: \(nativeCategory))")
|
||||
var options: AVAudioSession.CategoryOptions = []
|
||||
switch type {
|
||||
case .play:
|
||||
break
|
||||
case .playWithPossiblePortOverride:
|
||||
if case .playAndRecord = nativeCategory {
|
||||
if #available(iOSApplicationExtension 10.0, iOS 10.0, *) {
|
||||
options.insert(.allowBluetoothA2DP)
|
||||
} else {
|
||||
options.insert(.allowBluetooth)
|
||||
}
|
||||
}
|
||||
case .record, .voiceCall:
|
||||
options.insert(.allowBluetooth)
|
||||
}
|
||||
print("ManagedAudioSession setting active true")
|
||||
if #available(iOSApplicationExtension 11.0, iOS 11.0, *) {
|
||||
try AVAudioSession.sharedInstance().setCategory(nativeCategoryForType(type, headphones: self.isHeadsetPluggedInValue), mode: type == .voiceCall ? .voiceChat : .default, policy: .default, options: options)
|
||||
try AVAudioSession.sharedInstance().setCategory(nativeCategory, mode: type == .voiceCall ? .voiceChat : .default, policy: .default, options: options)
|
||||
} else {
|
||||
AVAudioSession.sharedInstance().perform(NSSelectorFromString("setCategory:error:"), with: nativeCategoryForType(type, headphones: self.isHeadsetPluggedInValue))
|
||||
AVAudioSession.sharedInstance().perform(NSSelectorFromString("setCategory:error:"), with: nativeCategory)
|
||||
try AVAudioSession.sharedInstance().setMode(type == .voiceCall ? .voiceChat : .default)
|
||||
}
|
||||
} catch let error {
|
||||
@ -716,12 +725,8 @@ public final class ManagedAudioSession {
|
||||
}
|
||||
}
|
||||
case .speakerIfNoHeadphones:
|
||||
if !self.isHeadsetPluggedInValue {
|
||||
try AVAudioSession.sharedInstance().overrideOutputAudioPort(.speaker)
|
||||
} else {
|
||||
try AVAudioSession.sharedInstance().overrideOutputAudioPort(.none)
|
||||
}
|
||||
}
|
||||
|
||||
if resetToBuiltin {
|
||||
var updatedType = type
|
||||
@ -778,9 +783,11 @@ public final class ManagedAudioSession {
|
||||
|
||||
private func updateOutputMode(_ outputMode: AudioSessionOutputMode) {
|
||||
if let (type, currentOutputMode) = self.currentTypeAndOutputMode, currentOutputMode != outputMode {
|
||||
self.currentTypeAndOutputMode = (type, outputMode)
|
||||
//self.currentTypeAndOutputMode = (type, outputMode)
|
||||
do {
|
||||
try self.setupOutputMode(outputMode, type: type)
|
||||
try self.setup(type: type, outputMode: outputMode, activateNow: true)
|
||||
//try self.setupOutputMode(outputMode, type: type)
|
||||
//try self.activate()
|
||||
} catch let error {
|
||||
print("ManagedAudioSession overrideOutputAudioPort error \(error)")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user