mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Live streaming improvements
This commit is contained in:
parent
6037c9041a
commit
8cc282e2c3
@ -55,7 +55,7 @@
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AVCodec *opus_decoder = avcodec_find_decoder(AV_CODEC_ID_OPUS);
|
const AVCodec *opus_decoder = avcodec_find_decoder(AV_CODEC_ID_AAC);
|
||||||
if (!opus_decoder) {
|
if (!opus_decoder) {
|
||||||
fprintf(stderr, "Could not find Opus decoder\n");
|
fprintf(stderr, "Could not find Opus decoder\n");
|
||||||
ret = AVERROR_UNKNOWN;
|
ret = AVERROR_UNKNOWN;
|
||||||
|
@ -553,6 +553,24 @@ final class MediaStreamVideoComponent: Component {
|
|||||||
livePlayerView.frame = newVideoFrame
|
livePlayerView.frame = newVideoFrame
|
||||||
livePlayerView.layer.cornerRadius = videoCornerRadius
|
livePlayerView.layer.cornerRadius = videoCornerRadius
|
||||||
livePlayerView.update(size: newVideoFrame.size)
|
livePlayerView.update(size: newVideoFrame.size)
|
||||||
|
|
||||||
|
var pictureInPictureController: AVPictureInPictureController? = nil
|
||||||
|
if #available(iOS 15.0, *) {
|
||||||
|
pictureInPictureController = AVPictureInPictureController(contentSource: AVPictureInPictureController.ContentSource(playerLayer: livePlayerView.playerLayer))
|
||||||
|
pictureInPictureController?.playerLayer.masksToBounds = false
|
||||||
|
pictureInPictureController?.playerLayer.cornerRadius = 10
|
||||||
|
} else if AVPictureInPictureController.isPictureInPictureSupported() {
|
||||||
|
pictureInPictureController = AVPictureInPictureController.init(playerLayer: AVPlayerLayer(player: AVPlayer()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pictureInPictureController?.delegate = self
|
||||||
|
if #available(iOS 14.2, *) {
|
||||||
|
pictureInPictureController?.canStartPictureInPictureAutomaticallyFromInline = true
|
||||||
|
}
|
||||||
|
if #available(iOS 14.0, *) {
|
||||||
|
pictureInPictureController?.requiresLinearPlayback = true
|
||||||
|
}
|
||||||
|
self.pictureInPictureController = pictureInPictureController
|
||||||
}
|
}
|
||||||
if let livePlayerView = self.livePlayerView {
|
if let livePlayerView = self.livePlayerView {
|
||||||
videoFrameUpdateTransition.setFrame(view: livePlayerView, frame: newVideoFrame, completion: nil)
|
videoFrameUpdateTransition.setFrame(view: livePlayerView, frame: newVideoFrame, completion: nil)
|
||||||
@ -792,14 +810,15 @@ private final class ProxyVideoView: UIView {
|
|||||||
private let id: Int64
|
private let id: Int64
|
||||||
private let player: AVPlayer
|
private let player: AVPlayer
|
||||||
private let playerItem: AVPlayerItem
|
private let playerItem: AVPlayerItem
|
||||||
private let playerLayer: AVPlayerLayer
|
let playerLayer: AVPlayerLayer
|
||||||
|
|
||||||
private var contextDisposable: Disposable?
|
private var contextDisposable: Disposable?
|
||||||
|
|
||||||
private var failureObserverId: AnyObject?
|
private var failureObserverId: AnyObject?
|
||||||
private var errorObserverId: AnyObject?
|
private var errorObserverId: AnyObject?
|
||||||
|
private var rateObserver: NSKeyValueObservation?
|
||||||
|
|
||||||
private var server: AnyObject?
|
private var isActiveDisposable: Disposable?
|
||||||
|
|
||||||
init(context: AccountContext, call: PresentationGroupCallImpl) {
|
init(context: AccountContext, call: PresentationGroupCallImpl) {
|
||||||
self.call = call
|
self.call = call
|
||||||
@ -825,10 +844,30 @@ private final class ProxyVideoView: UIView {
|
|||||||
self.errorObserverId = NotificationCenter.default.addObserver(forName: AVPlayerItem.newErrorLogEntryNotification, object: playerItem, queue: .main, using: { notification in
|
self.errorObserverId = NotificationCenter.default.addObserver(forName: AVPlayerItem.newErrorLogEntryNotification, object: playerItem, queue: .main, using: { notification in
|
||||||
print("Player Error: \(notification.description)")
|
print("Player Error: \(notification.description)")
|
||||||
})
|
})
|
||||||
|
self.rateObserver = self.player.observe(\.rate, changeHandler: { [weak self] _, change in
|
||||||
|
guard let self else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
print("Player rate: \(self.player.rate)")
|
||||||
|
})
|
||||||
|
|
||||||
self.layer.addSublayer(self.playerLayer)
|
self.layer.addSublayer(self.playerLayer)
|
||||||
|
|
||||||
//self.contextDisposable = ResourceAdaptor.shared.addContext(id: self.id, context: context, fileReference: fileReference)
|
self.isActiveDisposable = (context.sharedContext.applicationBindings.applicationIsActive
|
||||||
|
|> distinctUntilChanged
|
||||||
|
|> deliverOnMainQueue).start(next: { [weak self] isActive in
|
||||||
|
guard let self else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if isActive {
|
||||||
|
self.playerLayer.player = self.player
|
||||||
|
if self.player.rate == 0.0 {
|
||||||
|
self.player.play()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.playerLayer.player = nil
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
self.player.play()
|
self.player.play()
|
||||||
}
|
}
|
||||||
@ -845,6 +884,10 @@ private final class ProxyVideoView: UIView {
|
|||||||
if let errorObserverId = self.errorObserverId {
|
if let errorObserverId = self.errorObserverId {
|
||||||
NotificationCenter.default.removeObserver(errorObserverId)
|
NotificationCenter.default.removeObserver(errorObserverId)
|
||||||
}
|
}
|
||||||
|
if let rateObserver = self.rateObserver {
|
||||||
|
rateObserver.invalidate()
|
||||||
|
}
|
||||||
|
self.isActiveDisposable?.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
func update(size: CGSize) {
|
func update(size: CGSize) {
|
||||||
|
@ -1378,6 +1378,8 @@ private func infoItems(data: PeerInfoScreenData?, context: AccountContext, prese
|
|||||||
context.sharedContext.applicationBindings.openUrl(url)
|
context.sharedContext.applicationBindings.openUrl(url)
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
currentPeerInfoSection = .peerInfoTrailing
|
||||||
} else if actionButton != nil {
|
} else if actionButton != nil {
|
||||||
//TODO:localize
|
//TODO:localize
|
||||||
items[currentPeerInfoSection]!.append(PeerInfoScreenCommentItem(id: 800, text: "By launching this mini app, you agree to the [Terms of Service for Mini Apps](https://telegram.org/privacy).", linkAction: { action in
|
items[currentPeerInfoSection]!.append(PeerInfoScreenCommentItem(id: 800, text: "By launching this mini app, you agree to the [Terms of Service for Mini Apps](https://telegram.org/privacy).", linkAction: { action in
|
||||||
@ -1385,9 +1387,7 @@ private func infoItems(data: PeerInfoScreenData?, context: AccountContext, prese
|
|||||||
context.sharedContext.applicationBindings.openUrl(url)
|
context.sharedContext.applicationBindings.openUrl(url)
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
}
|
|
||||||
|
|
||||||
if actionButton != nil {
|
|
||||||
currentPeerInfoSection = .peerInfoTrailing
|
currentPeerInfoSection = .peerInfoTrailing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user