mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-07 17:30:12 +00:00
Various Fixes
This commit is contained in:
parent
1f0646541d
commit
c9d4c266dd
@ -182,12 +182,12 @@ private final class LegacyComponentsGlobalsProviderImpl: NSObject, LegacyCompone
|
|||||||
let convertedType: ManagedAudioSessionType
|
let convertedType: ManagedAudioSessionType
|
||||||
switch type {
|
switch type {
|
||||||
case TGAudioSessionTypePlayAndRecord, TGAudioSessionTypePlayAndRecordHeadphones:
|
case TGAudioSessionTypePlayAndRecord, TGAudioSessionTypePlayAndRecordHeadphones:
|
||||||
convertedType = .record(speaker: false)
|
convertedType = .recordWithOthers
|
||||||
default:
|
default:
|
||||||
convertedType = .play
|
convertedType = .play
|
||||||
}
|
}
|
||||||
let disposable = legacyContext.sharedContext.mediaManager.audioSession.push(audioSessionType: convertedType, once: true, activate: { _ in
|
let disposable = legacyContext.sharedContext.mediaManager.audioSession.push(audioSessionType: convertedType, once: true, activate: { _ in
|
||||||
}, deactivate: {
|
}, deactivate: { _ in
|
||||||
interrupted?()
|
interrupted?()
|
||||||
return .complete()
|
return .complete()
|
||||||
})
|
})
|
||||||
|
|||||||
@ -515,7 +515,7 @@ private final class AudioPlayerRendererContext {
|
|||||||
|
|
||||||
switch self.audioSession {
|
switch self.audioSession {
|
||||||
case let .manager(manager):
|
case let .manager(manager):
|
||||||
self.audioSessionDisposable.set(manager.push(audioSessionType: self.ambient ? .ambient : (self.playAndRecord ? .playWithPossiblePortOverride : .play), outputMode: self.forceAudioToSpeaker ? .speakerIfNoHeadphones : .system, once: true, manualActivate: { [weak self] control in
|
self.audioSessionDisposable.set(manager.push(audioSessionType: self.ambient ? .ambient : (self.playAndRecord ? .playWithPossiblePortOverride : .play), outputMode: self.forceAudioToSpeaker ? .speakerIfNoHeadphones : .system, once: self.ambient, manualActivate: { [weak self] control in
|
||||||
audioPlayerRendererQueue.async {
|
audioPlayerRendererQueue.async {
|
||||||
if let strongSelf = self {
|
if let strongSelf = self {
|
||||||
strongSelf.audioSessionControl = control
|
strongSelf.audioSessionControl = control
|
||||||
@ -532,13 +532,15 @@ private final class AudioPlayerRendererContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, deactivate: { [weak self] in
|
}, deactivate: { [weak self] temporary in
|
||||||
return Signal { subscriber in
|
return Signal { subscriber in
|
||||||
audioPlayerRendererQueue.async {
|
audioPlayerRendererQueue.async {
|
||||||
if let strongSelf = self {
|
if let strongSelf = self {
|
||||||
strongSelf.audioSessionControl = nil
|
strongSelf.audioSessionControl = nil
|
||||||
strongSelf.audioPaused()
|
if !temporary {
|
||||||
strongSelf.stop()
|
strongSelf.audioPaused()
|
||||||
|
strongSelf.stop()
|
||||||
|
}
|
||||||
subscriber.putCompletion()
|
subscriber.putCompletion()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -233,7 +233,7 @@ public func playSound(context: AccountContext, sound: PeerMessageSound, defaultS
|
|||||||
currentPlayer?.play()
|
currentPlayer?.play()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, deactivate: {
|
}, deactivate: { _ in
|
||||||
return Signal { subscriber in
|
return Signal { subscriber in
|
||||||
Queue.mainQueue().async {
|
Queue.mainQueue().async {
|
||||||
currentPlayer?.stop()
|
currentPlayer?.stop()
|
||||||
|
|||||||
@ -21,6 +21,7 @@ public enum ManagedAudioSessionType: Equatable {
|
|||||||
case record(speaker: Bool)
|
case record(speaker: Bool)
|
||||||
case voiceCall
|
case voiceCall
|
||||||
case videoCall
|
case videoCall
|
||||||
|
case recordWithOthers
|
||||||
|
|
||||||
var isPlay: Bool {
|
var isPlay: Bool {
|
||||||
switch self {
|
switch self {
|
||||||
@ -38,7 +39,7 @@ private func nativeCategoryForType(_ type: ManagedAudioSessionType, headphones:
|
|||||||
return .ambient
|
return .ambient
|
||||||
case .play:
|
case .play:
|
||||||
return .playback
|
return .playback
|
||||||
case .record, .voiceCall, .videoCall:
|
case .record, .recordWithOthers, .voiceCall, .videoCall:
|
||||||
return .playAndRecord
|
return .playAndRecord
|
||||||
case .playWithPossiblePortOverride:
|
case .playWithPossiblePortOverride:
|
||||||
if headphones {
|
if headphones {
|
||||||
@ -114,7 +115,7 @@ private final class HolderRecord {
|
|||||||
let audioSessionType: ManagedAudioSessionType
|
let audioSessionType: ManagedAudioSessionType
|
||||||
let control: ManagedAudioSessionControl
|
let control: ManagedAudioSessionControl
|
||||||
let activate: (ManagedAudioSessionControl) -> Void
|
let activate: (ManagedAudioSessionControl) -> Void
|
||||||
let deactivate: () -> Signal<Void, NoError>
|
let deactivate: (Bool) -> Signal<Void, NoError>
|
||||||
let headsetConnectionStatusChanged: (Bool) -> Void
|
let headsetConnectionStatusChanged: (Bool) -> Void
|
||||||
let availableOutputsChanged: ([AudioSessionOutput], AudioSessionOutput?) -> Void
|
let availableOutputsChanged: ([AudioSessionOutput], AudioSessionOutput?) -> Void
|
||||||
let once: Bool
|
let once: Bool
|
||||||
@ -122,7 +123,7 @@ private final class HolderRecord {
|
|||||||
var active: Bool = false
|
var active: Bool = false
|
||||||
var deactivatingDisposable: Disposable? = nil
|
var deactivatingDisposable: Disposable? = nil
|
||||||
|
|
||||||
init(id: Int32, audioSessionType: ManagedAudioSessionType, control: ManagedAudioSessionControl, activate: @escaping (ManagedAudioSessionControl) -> Void, deactivate: @escaping () -> Signal<Void, NoError>, headsetConnectionStatusChanged: @escaping (Bool) -> Void, availableOutputsChanged: @escaping ([AudioSessionOutput], AudioSessionOutput?) -> Void, once: Bool, outputMode: AudioSessionOutputMode) {
|
init(id: Int32, audioSessionType: ManagedAudioSessionType, control: ManagedAudioSessionControl, activate: @escaping (ManagedAudioSessionControl) -> Void, deactivate: @escaping (Bool) -> Signal<Void, NoError>, headsetConnectionStatusChanged: @escaping (Bool) -> Void, availableOutputsChanged: @escaping ([AudioSessionOutput], AudioSessionOutput?) -> Void, once: Bool, outputMode: AudioSessionOutputMode) {
|
||||||
self.id = id
|
self.id = id
|
||||||
self.audioSessionType = audioSessionType
|
self.audioSessionType = audioSessionType
|
||||||
self.control = control
|
self.control = control
|
||||||
@ -431,7 +432,7 @@ public final class ManagedAudioSession {
|
|||||||
return AVAudioSession.sharedInstance().secondaryAudioShouldBeSilencedHint
|
return AVAudioSession.sharedInstance().secondaryAudioShouldBeSilencedHint
|
||||||
}
|
}
|
||||||
|
|
||||||
public func push(audioSessionType: ManagedAudioSessionType, outputMode: AudioSessionOutputMode = .system, once: Bool = false, activate: @escaping (AudioSessionActivationState) -> Void, deactivate: @escaping () -> Signal<Void, NoError>) -> Disposable {
|
public func push(audioSessionType: ManagedAudioSessionType, outputMode: AudioSessionOutputMode = .system, once: Bool = false, activate: @escaping (AudioSessionActivationState) -> Void, deactivate: @escaping (Bool) -> Signal<Void, NoError>) -> Disposable {
|
||||||
return self.push(audioSessionType: audioSessionType, once: once, manualActivate: { control in
|
return self.push(audioSessionType: audioSessionType, once: once, manualActivate: { control in
|
||||||
control.setupAndActivate(synchronous: false, { state in
|
control.setupAndActivate(synchronous: false, { state in
|
||||||
activate(state)
|
activate(state)
|
||||||
@ -439,7 +440,7 @@ public final class ManagedAudioSession {
|
|||||||
}, deactivate: deactivate)
|
}, deactivate: deactivate)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func push(audioSessionType: ManagedAudioSessionType, outputMode: AudioSessionOutputMode = .system, once: Bool = false, activateImmediately: Bool = false, manualActivate: @escaping (ManagedAudioSessionControl) -> Void, deactivate: @escaping () -> Signal<Void, NoError>, headsetConnectionStatusChanged: @escaping (Bool) -> Void = { _ in }, availableOutputsChanged: @escaping ([AudioSessionOutput], AudioSessionOutput?) -> Void = { _, _ in }) -> Disposable {
|
public func push(audioSessionType: ManagedAudioSessionType, outputMode: AudioSessionOutputMode = .system, once: Bool = false, activateImmediately: Bool = false, manualActivate: @escaping (ManagedAudioSessionControl) -> Void, deactivate: @escaping (Bool) -> Signal<Void, NoError>, headsetConnectionStatusChanged: @escaping (Bool) -> Void = { _ in }, availableOutputsChanged: @escaping ([AudioSessionOutput], AudioSessionOutput?) -> Void = { _, _ in }) -> Disposable {
|
||||||
let id = OSAtomicIncrement32(&self.nextId)
|
let id = OSAtomicIncrement32(&self.nextId)
|
||||||
let queue = self.queue
|
let queue = self.queue
|
||||||
queue.async {
|
queue.async {
|
||||||
@ -566,9 +567,12 @@ public final class ManagedAudioSession {
|
|||||||
}
|
}
|
||||||
index += 1
|
index += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let lastIsRecordWithOthers = self.holders.last?.audioSessionType == .recordWithOthers
|
||||||
if !deactivating {
|
if !deactivating {
|
||||||
if let activeIndex = activeIndex {
|
if let activeIndex = activeIndex {
|
||||||
var deactivate = false
|
var deactivate = false
|
||||||
|
var temporary = false
|
||||||
|
|
||||||
if interruption {
|
if interruption {
|
||||||
if self.holders[activeIndex].audioSessionType != .voiceCall {
|
if self.holders[activeIndex].audioSessionType != .voiceCall {
|
||||||
@ -576,7 +580,10 @@ public final class ManagedAudioSession {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if activeIndex != self.holders.count - 1 {
|
if activeIndex != self.holders.count - 1 {
|
||||||
if self.holders[activeIndex].audioSessionType == .voiceCall {
|
if lastIsRecordWithOthers {
|
||||||
|
deactivate = true
|
||||||
|
temporary = true
|
||||||
|
} else if self.holders[activeIndex].audioSessionType == .voiceCall {
|
||||||
deactivate = false
|
deactivate = false
|
||||||
} else {
|
} else {
|
||||||
deactivate = true
|
deactivate = true
|
||||||
@ -587,7 +594,7 @@ public final class ManagedAudioSession {
|
|||||||
if deactivate {
|
if deactivate {
|
||||||
self.holders[activeIndex].active = false
|
self.holders[activeIndex].active = false
|
||||||
let id = self.holders[activeIndex].id
|
let id = self.holders[activeIndex].id
|
||||||
self.holders[activeIndex].deactivatingDisposable = (self.holders[activeIndex].deactivate()
|
self.holders[activeIndex].deactivatingDisposable = (self.holders[activeIndex].deactivate(temporary)
|
||||||
|> deliverOn(self.queue)).start(completed: { [weak self] in
|
|> deliverOn(self.queue)).start(completed: { [weak self] in
|
||||||
guard let strongSelf = self else {
|
guard let strongSelf = self else {
|
||||||
return
|
return
|
||||||
@ -726,21 +733,24 @@ public final class ManagedAudioSession {
|
|||||||
options.insert(.allowBluetooth)
|
options.insert(.allowBluetooth)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case .record, .voiceCall, .videoCall:
|
case .record, .recordWithOthers, .voiceCall, .videoCall:
|
||||||
options.insert(.allowBluetooth)
|
options.insert(.allowBluetooth)
|
||||||
}
|
}
|
||||||
managedAudioSessionLog("ManagedAudioSession setting active true")
|
managedAudioSessionLog("ManagedAudioSession setting active true")
|
||||||
let mode: AVAudioSession.Mode
|
let mode: AVAudioSession.Mode
|
||||||
switch type {
|
switch type {
|
||||||
case .voiceCall:
|
case .voiceCall:
|
||||||
mode = .voiceChat
|
mode = .voiceChat
|
||||||
options.insert(.mixWithOthers)
|
options.insert(.mixWithOthers)
|
||||||
case .videoCall:
|
case .videoCall:
|
||||||
mode = .videoChat
|
mode = .videoChat
|
||||||
options.insert(.mixWithOthers)
|
options.insert(.mixWithOthers)
|
||||||
default:
|
case .recordWithOthers:
|
||||||
mode = .default
|
mode = .videoRecording
|
||||||
}
|
options.insert(.mixWithOthers)
|
||||||
|
default:
|
||||||
|
mode = .default
|
||||||
|
}
|
||||||
if #available(iOSApplicationExtension 11.0, iOS 11.0, *) {
|
if #available(iOSApplicationExtension 11.0, iOS 11.0, *) {
|
||||||
try AVAudioSession.sharedInstance().setCategory(nativeCategory, mode: mode, policy: .default, options: options)
|
try AVAudioSession.sharedInstance().setCategory(nativeCategory, mode: mode, policy: .default, options: options)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -391,7 +391,7 @@ public final class PresentationCallImpl: PresentationCall {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, deactivate: { [weak self] in
|
}, deactivate: { [weak self] _ in
|
||||||
return Signal { subscriber in
|
return Signal { subscriber in
|
||||||
Queue.mainQueue().async {
|
Queue.mainQueue().async {
|
||||||
if let strongSelf = self {
|
if let strongSelf = self {
|
||||||
|
|||||||
@ -662,7 +662,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall {
|
|||||||
strongSelf.updateSessionState(internalState: strongSelf.internalState, audioSessionControl: control)
|
strongSelf.updateSessionState(internalState: strongSelf.internalState, audioSessionControl: control)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, deactivate: { [weak self] in
|
}, deactivate: { [weak self] _ in
|
||||||
return Signal { subscriber in
|
return Signal { subscriber in
|
||||||
Queue.mainQueue().async {
|
Queue.mainQueue().async {
|
||||||
if let strongSelf = self {
|
if let strongSelf = self {
|
||||||
|
|||||||
@ -199,6 +199,9 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if item.message.id.namespace == Namespaces.Message.Local {
|
||||||
|
notConsumed = true
|
||||||
|
}
|
||||||
|
|
||||||
var updatedPlaybackStatus: Signal<FileMediaResourceStatus, NoError>?
|
var updatedPlaybackStatus: Signal<FileMediaResourceStatus, NoError>?
|
||||||
if let updatedFile = updatedFile, updatedMedia || updatedMessageId {
|
if let updatedFile = updatedFile, updatedMedia || updatedMessageId {
|
||||||
@ -917,6 +920,7 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var animatedFadeIn = false
|
||||||
func animateFromSnapshot(snapshotView: UIView, transition: CombinedTransition) {
|
func animateFromSnapshot(snapshotView: UIView, transition: CombinedTransition) {
|
||||||
guard let videoFrame = self.videoFrame else {
|
guard let videoFrame = self.videoFrame else {
|
||||||
return
|
return
|
||||||
@ -934,9 +938,12 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode {
|
|||||||
|
|
||||||
transition.horizontal.animateTransformScale(node: self, from: 1.0 / scale)
|
transition.horizontal.animateTransformScale(node: self, from: 1.0 / scale)
|
||||||
|
|
||||||
self.dateAndStatusNode.layer.animateAlpha(from: 0.0, to: self.dateAndStatusNode.alpha, duration: 0.15, delay: 0.18)
|
if !self.animatedFadeIn {
|
||||||
if let durationNode = self.durationNode {
|
self.animatedFadeIn = true
|
||||||
durationNode.layer.animateAlpha(from: 0.0, to: durationNode.alpha, duration: 0.15, delay: 0.18)
|
self.dateAndStatusNode.layer.animateAlpha(from: 0.0, to: self.dateAndStatusNode.alpha, duration: 0.15, delay: 0.18)
|
||||||
|
if let durationNode = self.durationNode {
|
||||||
|
durationNode.layer.animateAlpha(from: 0.0, to: durationNode.alpha, duration: 0.15, delay: 0.18)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -402,7 +402,7 @@ final class ManagedAudioRecorderContext {
|
|||||||
strongSelf.audioSessionAcquired(headset: state.isHeadsetConnected)
|
strongSelf.audioSessionAcquired(headset: state.isHeadsetConnected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, deactivate: { [weak self] in
|
}, deactivate: { [weak self] _ in
|
||||||
return Signal { subscriber in
|
return Signal { subscriber in
|
||||||
queue.async {
|
queue.async {
|
||||||
if let strongSelf = self {
|
if let strongSelf = self {
|
||||||
|
|||||||
@ -386,7 +386,7 @@ private final class PlatformVideoContentNode: ASDisplayNode, UniversalVideoConte
|
|||||||
self.audioSessionDisposable.set(self.audioSessionManager.push(audioSessionType: .play, activate: { [weak self] _ in
|
self.audioSessionDisposable.set(self.audioSessionManager.push(audioSessionType: .play, activate: { [weak self] _ in
|
||||||
self?.hasAudioSession = true
|
self?.hasAudioSession = true
|
||||||
self?.player.play()
|
self?.player.play()
|
||||||
}, deactivate: { [weak self] in
|
}, deactivate: { [weak self] _ in
|
||||||
self?.hasAudioSession = false
|
self?.hasAudioSession = false
|
||||||
self?.player.pause()
|
self?.player.pause()
|
||||||
return .complete()
|
return .complete()
|
||||||
|
|||||||
@ -224,7 +224,7 @@ private final class SystemVideoContentNode: ASDisplayNode, UniversalVideoContent
|
|||||||
self.audioSessionDisposable.set(self.audioSessionManager.push(audioSessionType: .play, activate: { [weak self] _ in
|
self.audioSessionDisposable.set(self.audioSessionManager.push(audioSessionType: .play, activate: { [weak self] _ in
|
||||||
self?.hasAudioSession = true
|
self?.hasAudioSession = true
|
||||||
self?.player.play()
|
self?.player.play()
|
||||||
}, deactivate: { [weak self] in
|
}, deactivate: { [weak self] _ in
|
||||||
self?.hasAudioSession = false
|
self?.hasAudioSession = false
|
||||||
self?.player.pause()
|
self?.player.pause()
|
||||||
return .complete()
|
return .complete()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user