Native picture in picture support

This commit is contained in:
Ali
2021-11-02 16:04:39 +04:00
parent cf624bcad3
commit 17c84b85a0
17 changed files with 469 additions and 87 deletions

View File

@@ -7,6 +7,7 @@ import TelegramCore
import Display
import TelegramAudio
import UniversalMediaPlayer
import AVFoundation
public protocol UniversalVideoContentNode: AnyObject {
var ready: Signal<Void, NoError> { get }
@@ -29,6 +30,7 @@ public protocol UniversalVideoContentNode: AnyObject {
func removePlaybackCompleted(_ index: Int)
func fetchControl(_ control: UniversalVideoNodeFetchControl)
func notifyPlaybackControlsHidden(_ hidden: Bool)
func setCanPlaybackWithoutHierarchy(_ canPlaybackWithoutHierarchy: Bool)
}
public protocol UniversalVideoContent {
@@ -332,4 +334,36 @@ public final class UniversalVideoNode: ASDisplayNode {
self.decoration.tap()
}
}
public func getVideoLayer() -> AVSampleBufferDisplayLayer? {
guard let contentNode = self.contentNode else {
return nil
}
func findVideoLayer(layer: CALayer) -> AVSampleBufferDisplayLayer? {
if let layer = layer as? AVSampleBufferDisplayLayer {
return layer
}
if let sublayers = layer.sublayers {
for sublayer in sublayers {
if let result = findVideoLayer(layer: sublayer) {
return result
}
}
}
return nil
}
return findVideoLayer(layer: contentNode.layer)
}
public func setCanPlaybackWithoutHierarchy(_ canPlaybackWithoutHierarchy: Bool) {
self.manager.withUniversalVideoContent(id: self.content.id, { contentNode in
if let contentNode = contentNode {
contentNode.setCanPlaybackWithoutHierarchy(canPlaybackWithoutHierarchy)
}
})
}
}