mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-17 11:50:56 +00:00
Don't show video in background
This commit is contained in:
parent
39ebfb356e
commit
9c7dc185fe
@ -493,6 +493,9 @@ public final class MediaStreamComponent: CombinedComponent {
|
|||||||
|
|
||||||
let isPictureInPictureSupported: Bool
|
let isPictureInPictureSupported: Bool
|
||||||
|
|
||||||
|
private(set) var isVisibleInHierarchy: Bool = false
|
||||||
|
private var isVisibleInHierarchyDisposable: Disposable?
|
||||||
|
|
||||||
private var scheduledDismissUITimer: SwiftSignalKit.Timer?
|
private var scheduledDismissUITimer: SwiftSignalKit.Timer?
|
||||||
|
|
||||||
init(call: PresentationGroupCallImpl) {
|
init(call: PresentationGroupCallImpl) {
|
||||||
@ -543,11 +546,23 @@ public final class MediaStreamComponent: CombinedComponent {
|
|||||||
})
|
})
|
||||||
|
|
||||||
let _ = call.accountContext.engine.calls.getGroupCallStreamCredentials(peerId: call.peerId, revokePreviousCredentials: false).start()
|
let _ = call.accountContext.engine.calls.getGroupCallStreamCredentials(peerId: call.peerId, revokePreviousCredentials: false).start()
|
||||||
|
|
||||||
|
self.isVisibleInHierarchyDisposable = (call.accountContext.sharedContext.applicationBindings.applicationInForeground
|
||||||
|
|> deliverOnMainQueue).start(next: { [weak self] inForeground in
|
||||||
|
guard let strongSelf = self else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if strongSelf.isVisibleInHierarchy != inForeground {
|
||||||
|
strongSelf.isVisibleInHierarchy = inForeground
|
||||||
|
strongSelf.updated(transition: .immediate)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
self.stateDisposable?.dispose()
|
self.stateDisposable?.dispose()
|
||||||
self.infoDisposable?.dispose()
|
self.infoDisposable?.dispose()
|
||||||
|
self.isVisibleInHierarchyDisposable?.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
func toggleDisplayUI() {
|
func toggleDisplayUI() {
|
||||||
@ -617,6 +632,7 @@ public final class MediaStreamComponent: CombinedComponent {
|
|||||||
component: MediaStreamVideoComponent(
|
component: MediaStreamVideoComponent(
|
||||||
call: context.component.call,
|
call: context.component.call,
|
||||||
hasVideo: context.state.hasVideo,
|
hasVideo: context.state.hasVideo,
|
||||||
|
isVisible: environment.isVisible && context.state.isVisibleInHierarchy,
|
||||||
activatePictureInPicture: activatePictureInPicture,
|
activatePictureInPicture: activatePictureInPicture,
|
||||||
bringBackControllerForPictureInPictureDeactivation: { [weak call] completed in
|
bringBackControllerForPictureInPictureDeactivation: { [weak call] completed in
|
||||||
guard let call = call else {
|
guard let call = call else {
|
||||||
|
|||||||
@ -8,12 +8,14 @@ import AVKit
|
|||||||
final class MediaStreamVideoComponent: Component {
|
final class MediaStreamVideoComponent: Component {
|
||||||
let call: PresentationGroupCallImpl
|
let call: PresentationGroupCallImpl
|
||||||
let hasVideo: Bool
|
let hasVideo: Bool
|
||||||
|
let isVisible: Bool
|
||||||
let activatePictureInPicture: ActionSlot<Action<Void>>
|
let activatePictureInPicture: ActionSlot<Action<Void>>
|
||||||
let bringBackControllerForPictureInPictureDeactivation: (@escaping () -> Void) -> Void
|
let bringBackControllerForPictureInPictureDeactivation: (@escaping () -> Void) -> Void
|
||||||
|
|
||||||
init(call: PresentationGroupCallImpl, hasVideo: Bool, activatePictureInPicture: ActionSlot<Action<Void>>, bringBackControllerForPictureInPictureDeactivation: @escaping (@escaping () -> Void) -> Void) {
|
init(call: PresentationGroupCallImpl, hasVideo: Bool, isVisible: Bool, activatePictureInPicture: ActionSlot<Action<Void>>, bringBackControllerForPictureInPictureDeactivation: @escaping (@escaping () -> Void) -> Void) {
|
||||||
self.call = call
|
self.call = call
|
||||||
self.hasVideo = hasVideo
|
self.hasVideo = hasVideo
|
||||||
|
self.isVisible = isVisible
|
||||||
self.activatePictureInPicture = activatePictureInPicture
|
self.activatePictureInPicture = activatePictureInPicture
|
||||||
self.bringBackControllerForPictureInPictureDeactivation = bringBackControllerForPictureInPictureDeactivation
|
self.bringBackControllerForPictureInPictureDeactivation = bringBackControllerForPictureInPictureDeactivation
|
||||||
}
|
}
|
||||||
@ -25,6 +27,9 @@ final class MediaStreamVideoComponent: Component {
|
|||||||
if lhs.hasVideo != rhs.hasVideo {
|
if lhs.hasVideo != rhs.hasVideo {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if lhs.isVisible != rhs.isVisible {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -54,6 +59,8 @@ final class MediaStreamVideoComponent: Component {
|
|||||||
private var component: MediaStreamVideoComponent?
|
private var component: MediaStreamVideoComponent?
|
||||||
private var hadVideo: Bool = false
|
private var hadVideo: Bool = false
|
||||||
|
|
||||||
|
private weak var state: State?
|
||||||
|
|
||||||
override init(frame: CGRect) {
|
override init(frame: CGRect) {
|
||||||
self.blurTintView = UIView()
|
self.blurTintView = UIView()
|
||||||
self.blurTintView.backgroundColor = UIColor(white: 0.0, alpha: 0.55)
|
self.blurTintView.backgroundColor = UIColor(white: 0.0, alpha: 0.55)
|
||||||
@ -82,6 +89,8 @@ final class MediaStreamVideoComponent: Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func update(component: MediaStreamVideoComponent, availableSize: CGSize, state: State, transition: Transition) -> CGSize {
|
func update(component: MediaStreamVideoComponent, availableSize: CGSize, state: State, transition: Transition) -> CGSize {
|
||||||
|
self.state = state
|
||||||
|
|
||||||
if component.hasVideo, self.videoView == nil {
|
if component.hasVideo, self.videoView == nil {
|
||||||
if let input = component.call.video(endpointId: "unified") {
|
if let input = component.call.video(endpointId: "unified") {
|
||||||
if let videoBlurView = self.videoRenderingContext.makeView(input: input, blur: true) {
|
if let videoBlurView = self.videoRenderingContext.makeView(input: input, blur: true) {
|
||||||
@ -122,7 +131,15 @@ final class MediaStreamVideoComponent: Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let videoView = self.videoView {
|
if let videoView = self.videoView {
|
||||||
videoView.updateIsEnabled(true)
|
var isVideoVisible = component.isVisible
|
||||||
|
if let pictureInPictureController = self.pictureInPictureController {
|
||||||
|
if pictureInPictureController.isPictureInPictureActive {
|
||||||
|
isVideoVisible = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
videoView.updateIsEnabled(isVideoVisible)
|
||||||
|
|
||||||
var aspect = videoView.getAspect()
|
var aspect = videoView.getAspect()
|
||||||
if aspect <= 0.01 {
|
if aspect <= 0.01 {
|
||||||
aspect = 3.0 / 4.0
|
aspect = 3.0 / 4.0
|
||||||
@ -134,7 +151,8 @@ final class MediaStreamVideoComponent: Component {
|
|||||||
transition.withAnimation(.none).setFrame(view: videoView, frame: CGRect(origin: CGPoint(x: floor((availableSize.width - videoSize.width) / 2.0), y: floor((availableSize.height - videoSize.height) / 2.0)), size: videoSize), completion: nil)
|
transition.withAnimation(.none).setFrame(view: videoView, frame: CGRect(origin: CGPoint(x: floor((availableSize.width - videoSize.width) / 2.0), y: floor((availableSize.height - videoSize.height) / 2.0)), size: videoSize), completion: nil)
|
||||||
|
|
||||||
if let videoBlurView = self.videoBlurView {
|
if let videoBlurView = self.videoBlurView {
|
||||||
videoBlurView.updateIsEnabled(true)
|
videoBlurView.updateIsEnabled(component.isVisible)
|
||||||
|
|
||||||
transition.withAnimation(.none).setFrame(view: videoBlurView, frame: CGRect(origin: CGPoint(x: floor((availableSize.width - blurredVideoSize.width) / 2.0), y: floor((availableSize.height - blurredVideoSize.height) / 2.0)), size: blurredVideoSize), completion: nil)
|
transition.withAnimation(.none).setFrame(view: videoBlurView, frame: CGRect(origin: CGPoint(x: floor((availableSize.width - blurredVideoSize.width) / 2.0), y: floor((availableSize.height - blurredVideoSize.height) / 2.0)), size: blurredVideoSize), completion: nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -207,6 +225,14 @@ final class MediaStreamVideoComponent: Component {
|
|||||||
completionHandler(true)
|
completionHandler(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func pictureInPictureControllerWillStartPictureInPicture(_ pictureInPictureController: AVPictureInPictureController) {
|
||||||
|
self.state?.updated(transition: .immediate)
|
||||||
|
}
|
||||||
|
|
||||||
|
func pictureInPictureControllerDidStopPictureInPicture(_ pictureInPictureController: AVPictureInPictureController) {
|
||||||
|
self.state?.updated(transition: .immediate)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func makeView() -> View {
|
public func makeView() -> View {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user