Various fixes

This commit is contained in:
Ilya Laktyushin
2023-09-17 19:34:47 +04:00
parent 59940ae1ba
commit d9ffdd4ea4
3 changed files with 67 additions and 28 deletions

View File

@@ -272,7 +272,7 @@ func presentLegacyMediaPickerGallery(context: AccountContext, peer: EnginePeer?,
|> take(1)
|> deliverOnMainQueue).start(next: { sendWhenOnlineAvailable in
let legacySheetController = LegacyController(presentation: .custom, theme: presentationData.theme, initialLayout: nil)
let sheetController = TGMediaPickerSendActionSheetController(context: legacyController.context, isDark: true, sendButtonFrame: model.interfaceView.doneButtonFrame, canSendSilently: hasSilentPosting, canSendWhenOnline: sendWhenOnlineAvailable && effectiveHasSchedule, canSchedule: effectiveHasSchedule, reminder: reminder, hasTimer: false)
let sheetController = TGMediaPickerSendActionSheetController(context: legacyController.context, isDark: true, sendButtonFrame: model.interfaceView.doneButtonFrame, canSendSilently: hasSilentPosting, canSendWhenOnline: sendWhenOnlineAvailable && effectiveHasSchedule, canSchedule: effectiveHasSchedule, reminder: reminder, hasTimer: hasTimer)
let dismissImpl = { [weak model] in
model?.dismiss(true, false)
dismissAll()

View File

@@ -253,29 +253,39 @@ public class PremiumLimitDisplayComponent: Component {
positionAnimation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
self.badgeView.layer.add(positionAnimation, forKey: "appearance1")
let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation.z")
rotateAnimation.fromValue = 0.0 as NSNumber
rotateAnimation.toValue = -0.38 as NSNumber
rotateAnimation.duration = 0.15
rotateAnimation.fillMode = .forwards
rotateAnimation.timingFunction = CAMediaTimingFunction(name: .easeOut)
rotateAnimation.isRemovedOnCompletion = false
self.badgeView.layer.add(rotateAnimation, forKey: "appearance2")
Queue.mainQueue().after(0.5, {
let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation.z")
rotateAnimation.fromValue = 0.0 as NSNumber
rotateAnimation.toValue = 0.2 as NSNumber
rotateAnimation.duration = 0.2
rotateAnimation.fillMode = .forwards
rotateAnimation.timingFunction = CAMediaTimingFunction(name: .easeOut)
rotateAnimation.isRemovedOnCompletion = false
self.badgeView.layer.add(rotateAnimation, forKey: "appearance2")
let bounceAnimation = CABasicAnimation(keyPath: "transform.rotation.z")
bounceAnimation.fromValue = -0.38 as NSNumber
bounceAnimation.toValue = 0.05 as NSNumber
bounceAnimation.duration = 0.15
bounceAnimation.fillMode = .forwards
bounceAnimation.timingFunction = CAMediaTimingFunction(name: .easeOut)
bounceAnimation.isRemovedOnCompletion = false
self.badgeView.layer.add(bounceAnimation, forKey: "appearance3")
self.badgeView.layer.removeAnimation(forKey: "appearance2")
if !self.badgeView.isHidden {
self.hapticFeedback.impact(.light)
}
Queue.mainQueue().after(0.2) {
Queue.mainQueue().after(0.15) {
let returnAnimation = CABasicAnimation(keyPath: "transform.rotation.z")
returnAnimation.fromValue = 0.2 as NSNumber
returnAnimation.fromValue = 0.05 as NSNumber
returnAnimation.toValue = 0.0 as NSNumber
returnAnimation.duration = 0.18
returnAnimation.duration = 0.1
returnAnimation.fillMode = .forwards
returnAnimation.timingFunction = CAMediaTimingFunction(name: .easeIn)
self.badgeView.layer.add(returnAnimation, forKey: "appearance3")
self.badgeView.layer.removeAnimation(forKey: "appearance2")
self.badgeView.layer.add(returnAnimation, forKey: "appearance4")
self.badgeView.layer.removeAnimation(forKey: "appearance3")
}
})
@@ -285,7 +295,7 @@ public class PremiumLimitDisplayComponent: Component {
}
if let badgeText = component.badgeText {
self.badgeCountLabel.configure(with: badgeText, duration: from != nil ? 0.3 : 0.9)
self.badgeCountLabel.configure(with: badgeText, duration: from != nil ? 0.3 : 0.5)
}
}

View File

@@ -573,11 +573,9 @@ public final class MediaEditor {
// self.maybeGeneratePersonSegmentation(image)
}
if let audioTrack = self.values.audioTrack {
self.setAudioTrack(audioTrack)
self.setAudioTrackVolume(self.values.audioTrackVolume)
self.setAudioTrackTrimRange(self.values.audioTrackTrimRange, apply: true)
self.setAudioTrackOffset(self.values.audioTrackOffset, apply: true)
if let _ = self.values.audioTrack {
self.setupAudioPlayback()
self.updateAudioPlaybackRange()
}
if let player {
@@ -609,6 +607,19 @@ public final class MediaEditor {
startPlayback()
}
}
} else if let audioPlayer = self.audioPlayer {
let offset = self.values.audioTrackOffset ?? 0.0
let lowerBound = self.values.audioTrackTrimRange?.lowerBound ?? 0.0
let audioTime = CMTime(seconds: offset + lowerBound, preferredTimescale: CMTimeScale(1000))
audioPlayer.seek(to: audioTime, toleranceBefore: .zero, toleranceAfter: .zero)
if audioPlayer.status != .readyToPlay {
Queue.mainQueue().after(0.1) {
audioPlayer.play()
}
} else {
audioPlayer.play()
}
}
}
})
@@ -936,6 +947,10 @@ public final class MediaEditor {
} else {
if audioPlayer.status == .readyToPlay {
audioPlayer.setRate(rate, time: audioTime, atHostTime: futureTime)
if rate > 0.0 {
// audioPlayer.seek(to: audioTime, toleranceBefore: .zero, toleranceAfter: .zero)
audioPlayer.play()
}
} else {
audioPlayer.seek(to: audioTime, toleranceBefore: .zero, toleranceAfter: .zero)
if rate > 0.0 {
@@ -1059,15 +1074,23 @@ public final class MediaEditor {
}
}
if let audioTrack {
self.setupAudioPlayback()
}
private func setupAudioPlayback() {
if let audioTrack = self.values.audioTrack {
let path = fullDraftPath(peerId: self.context.account.peerId, path: audioTrack.path)
let audioAsset = AVURLAsset(url: URL(fileURLWithPath: path))
let playerItem = AVPlayerItem(asset: audioAsset)
let player = AVPlayer(playerItem: playerItem)
player.automaticallyWaitsToMinimizeStalling = false
self.audioPlayer = player
self.audioPlayer = player
self.maybeGenerateAudioSamples(asset: audioAsset)
if let volume = self.values.audioTrackVolume {
self.audioPlayer?.volume = Float(volume)
}
self.setupTimeObservers()
if !self.sourceIsVideo {
@@ -1081,9 +1104,8 @@ public final class MediaEditor {
return values.withUpdatedAudioTrackTrimRange(trimRange)
}
if apply, let trimRange {
let offset = self.values.audioTrackOffset ?? 0.0
self.audioPlayer?.currentItem?.forwardPlaybackEndTime = CMTime(seconds: offset + trimRange.upperBound, preferredTimescale: CMTimeScale(1000))
if apply, let _ = trimRange {
self.updateAudioPlaybackRange()
}
}
@@ -1094,9 +1116,7 @@ public final class MediaEditor {
if apply {
let offset = offset ?? 0.0
let duration = self.duration ?? 0.0
let lowerBound = self.values.audioTrackTrimRange?.lowerBound ?? 0.0
let upperBound = self.values.audioTrackTrimRange?.upperBound ?? duration
let audioTime: CMTime
if self.sourceIsVideo {
@@ -1105,7 +1125,7 @@ public final class MediaEditor {
} else {
audioTime = CMTime(seconds: offset + lowerBound, preferredTimescale: CMTimeScale(1000))
}
self.audioPlayer?.currentItem?.forwardPlaybackEndTime = CMTime(seconds: offset + upperBound, preferredTimescale: CMTimeScale(1000))
self.updateAudioPlaybackRange()
self.audioPlayer?.seek(to: audioTime, toleranceBefore: .zero, toleranceAfter: .zero)
if !self.sourceIsVideo {
self.audioPlayer?.play()
@@ -1113,6 +1133,15 @@ public final class MediaEditor {
}
}
private func updateAudioPlaybackRange() {
if let upperBound = self.values.audioTrackTrimRange?.upperBound {
let offset = self.values.audioTrackOffset ?? 0.0
self.audioPlayer?.currentItem?.forwardPlaybackEndTime = CMTime(seconds: offset + upperBound, preferredTimescale: CMTimeScale(1000))
} else {
self.audioPlayer?.currentItem?.forwardPlaybackEndTime = .invalid
}
}
public func setAudioTrackVolume(_ volume: CGFloat?) {
self.updateValues(mode: .skipRendering) { values in
return values.withUpdatedAudioTrackVolume(volume)