mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-10-09 03:20:48 +00:00
Camera and editor improvements
This commit is contained in:
parent
fc999d8042
commit
e9228cb9fa
@ -305,7 +305,7 @@ public final class MediaEditor {
|
||||
|
||||
let playerItem = AVPlayerItem(asset: asset)
|
||||
let player = AVPlayer(playerItem: playerItem)
|
||||
|
||||
player.automaticallyWaitsToMinimizeStalling = false
|
||||
if let transitionImage {
|
||||
let colors = mediaEditorGetGradientColors(from: transitionImage)
|
||||
subscriber.putNext((VideoTextureSource(player: player, renderTarget: renderTarget), nil, player, colors.0, colors.1))
|
||||
@ -348,6 +348,7 @@ public final class MediaEditor {
|
||||
if let asset {
|
||||
let playerItem = AVPlayerItem(asset: asset)
|
||||
let player = AVPlayer(playerItem: playerItem)
|
||||
player.automaticallyWaitsToMinimizeStalling = false
|
||||
subscriber.putNext((VideoTextureSource(player: player, renderTarget: renderTarget), nil, player, colors.0, colors.1))
|
||||
subscriber.putCompletion()
|
||||
}
|
||||
@ -422,7 +423,7 @@ public final class MediaEditor {
|
||||
self.player?.play()
|
||||
}
|
||||
})
|
||||
self.player?.play()
|
||||
player.playImmediately(atRate: 1.0)
|
||||
self.volumeFade = self.player?.fadeVolume(from: 0.0, to: 1.0, duration: 0.4)
|
||||
}
|
||||
}
|
||||
|
@ -221,7 +221,7 @@ final class MediaEditorRenderer: TextureConsumer {
|
||||
|
||||
if let onNextRender = self.onNextRender {
|
||||
self.onNextRender = nil
|
||||
Queue.mainQueue().after(0.1) {
|
||||
Queue.mainQueue().after(0.016) {
|
||||
onNextRender()
|
||||
}
|
||||
}
|
||||
|
@ -29,10 +29,7 @@ final class VideoTextureSource: NSObject, TextureSource, AVPlayerItemOutputPullD
|
||||
private weak var player: AVPlayer?
|
||||
private weak var playerItem: AVPlayerItem?
|
||||
private var playerItemOutput: AVPlayerItemVideoOutput?
|
||||
|
||||
private var playerItemStatusObservation: NSKeyValueObservation?
|
||||
private var playerItemObservation: NSKeyValueObservation?
|
||||
|
||||
|
||||
private var displayLink: CADisplayLink?
|
||||
|
||||
private let device: MTLDevice?
|
||||
@ -57,24 +54,12 @@ final class VideoTextureSource: NSObject, TextureSource, AVPlayerItemOutputPullD
|
||||
|
||||
super.init()
|
||||
|
||||
self.playerItemObservation = player.observe(\.currentItem, options: [.initial, .new], changeHandler: { [weak self] (player, change) in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
strongSelf.updatePlayerItem(player.currentItem)
|
||||
})
|
||||
self.updatePlayerItem(player.currentItem)
|
||||
}
|
||||
|
||||
deinit {
|
||||
self.playerItemObservation?.invalidate()
|
||||
self.playerItemStatusObservation?.invalidate()
|
||||
}
|
||||
|
||||
|
||||
func invalidate() {
|
||||
self.playerItemOutput?.setDelegate(nil, queue: nil)
|
||||
self.playerItemOutput = nil
|
||||
self.playerItemObservation?.invalidate()
|
||||
self.playerItemStatusObservation?.invalidate()
|
||||
self.displayLink?.invalidate()
|
||||
self.displayLink = nil
|
||||
}
|
||||
@ -88,18 +73,9 @@ final class VideoTextureSource: NSObject, TextureSource, AVPlayerItemOutputPullD
|
||||
}
|
||||
}
|
||||
self.playerItemOutput = nil
|
||||
self.playerItemStatusObservation?.invalidate()
|
||||
self.playerItemStatusObservation = nil
|
||||
|
||||
self.playerItem = playerItem
|
||||
self.playerItemStatusObservation = self.playerItem?.observe(\.status, options: [.initial, .new], changeHandler: { [weak self] item, change in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
if strongSelf.playerItem == item, item.status == .readyToPlay {
|
||||
strongSelf.handleReadyToPlay()
|
||||
}
|
||||
})
|
||||
self.handleReadyToPlay()
|
||||
}
|
||||
|
||||
private func handleReadyToPlay() {
|
||||
|
@ -252,22 +252,22 @@ final class MediaEditorScreenComponent: Component {
|
||||
view.layer.animateScale(from: 0.1, to: 1.0, duration: 0.2)
|
||||
}
|
||||
|
||||
var delay: Double = 0.0
|
||||
for button in buttons {
|
||||
if let view = button.view {
|
||||
view.layer.animatePosition(from: CGPoint(x: 0.0, y: 64.0), to: .zero, duration: 0.3, delay: delay, timingFunction: kCAMediaTimingFunctionSpring, additive: true)
|
||||
view.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2, delay: delay)
|
||||
view.layer.animateScale(from: 0.1, to: 1.0, duration: 0.2, delay: delay)
|
||||
delay += 0.05
|
||||
}
|
||||
}
|
||||
|
||||
if let view = self.doneButton.view {
|
||||
view.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2)
|
||||
view.layer.animateScale(from: 0.1, to: 1.0, duration: 0.2)
|
||||
}
|
||||
|
||||
if case .camera = source {
|
||||
var delay: Double = 0.0
|
||||
for button in buttons {
|
||||
if let view = button.view {
|
||||
view.layer.animatePosition(from: CGPoint(x: 0.0, y: 64.0), to: .zero, duration: 0.3, delay: delay, timingFunction: kCAMediaTimingFunctionSpring, additive: true)
|
||||
view.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2, delay: delay)
|
||||
view.layer.animateScale(from: 0.1, to: 1.0, duration: 0.2, delay: delay)
|
||||
delay += 0.05
|
||||
}
|
||||
}
|
||||
|
||||
if let view = self.saveButton.view {
|
||||
view.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2)
|
||||
view.layer.animateScale(from: 0.1, to: 1.0, duration: 0.2)
|
||||
@ -900,10 +900,10 @@ final class MediaEditorScreenComponent: Component {
|
||||
saveButtonView.layer.shadowOpacity = 0.35
|
||||
self.addSubview(saveButtonView)
|
||||
}
|
||||
|
||||
|
||||
let saveButtonAlpha = component.isSavingAvailable ? 1.0 : 0.3
|
||||
saveButtonView.isUserInteractionEnabled = component.isSavingAvailable
|
||||
|
||||
|
||||
transition.setPosition(view: saveButtonView, position: saveButtonFrame.center)
|
||||
transition.setBounds(view: saveButtonView, bounds: CGRect(origin: .zero, size: saveButtonFrame.size))
|
||||
transition.setScale(view: saveButtonView, scale: displayTopButtons ? 1.0 : 0.01)
|
||||
|
Loading…
x
Reference in New Issue
Block a user