Video message recording improvements

This commit is contained in:
Ilya Laktyushin
2024-01-13 21:46:02 +04:00
parent bb23f962b8
commit ebc8176850
5 changed files with 44 additions and 13 deletions

View File

@@ -71,7 +71,7 @@ enum CameraScreenTransition {
private let viewOnceButtonTag = GenericComponentViewTag()
private final class CameraScreenComponent: CombinedComponent {
private final class VideoMessageCameraScreenComponent: CombinedComponent {
typealias EnvironmentType = ViewControllerComponentContainer.Environment
let context: AccountContext
@@ -109,7 +109,7 @@ private final class CameraScreenComponent: CombinedComponent {
self.completion = completion
}
static func ==(lhs: CameraScreenComponent, rhs: CameraScreenComponent) -> Bool {
static func ==(lhs: VideoMessageCameraScreenComponent, rhs: VideoMessageCameraScreenComponent) -> Bool {
if lhs.context !== rhs.context {
return false
}
@@ -184,6 +184,9 @@ private final class CameraScreenComponent: CombinedComponent {
if let self, let controller = getController() {
self.startVideoRecording(pressing: !controller.scheduledLock)
controller.scheduledLock = false
if controller.recordingStartTime == nil {
controller.recordingStartTime = CACurrentMediaTime()
}
}
})
self.stopRecording.connect({ [weak self] _ in
@@ -241,7 +244,7 @@ private final class CameraScreenComponent: CombinedComponent {
let duration = initialDuration + recordingData.duration
if let self, let controller = self.getController() {
controller.updateCameraState({ $0.updatedDuration(duration) }, transition: .easeInOut(duration: 0.1))
if recordingData.duration > 59.0 {
if duration > 59.0 {
self.stopVideoRecording()
}
if isFirstRecording {
@@ -323,6 +326,10 @@ private final class CameraScreenComponent: CombinedComponent {
showViewOnce = true
}
if let controller = component.getController(), !controller.viewOnceAvailable {
showViewOnce = false
}
if !component.isPreviewing {
let flipButton = flipButton.update(
component: CameraButton(
@@ -942,7 +949,7 @@ public class VideoMessageCameraScreen: ViewController {
let componentSize = self.componentHost.update(
transition: transition,
component: AnyComponent(
CameraScreenComponent(
VideoMessageCameraScreenComponent(
context: self.context,
cameraState: self.cameraState,
isPreviewing: self.previewState != nil || self.transitioningToPreview,
@@ -1056,6 +1063,7 @@ public class VideoMessageCameraScreen: ViewController {
private let updatedPresentationData: (initial: PresentationData, signal: Signal<PresentationData, NoError>)?
private let inputPanelFrame: CGRect
fileprivate var allowLiveUpload: Bool
fileprivate var viewOnceAvailable: Bool
fileprivate let completion: (EnqueueMessage?) -> Void
@@ -1147,13 +1155,20 @@ public class VideoMessageCameraScreen: ViewController {
initialPlaceholder = self.camera?.transitionImage ?? .single(nil)
}
var approximateDuration: Double
if let recordingStartTime = self.recordingStartTime {
approximateDuration = CACurrentMediaTime() - recordingStartTime
} else {
approximateDuration = 1.0
}
let immediateResult: Signal<RecordedVideoData?, NoError> = initialPlaceholder
|> take(1)
|> mapToSignal { initialPlaceholder in
return videoFrames(asset: nil, count: count, initialPlaceholder: initialPlaceholder)
|> map { framesAndUpdateTimestamp in
return RecordedVideoData(
duration: 1.0,
duration: approximateDuration,
frames: framesAndUpdateTimestamp.0,
framesUpdateTimestamp: framesAndUpdateTimestamp.1,
trimRange: nil
@@ -1196,14 +1211,15 @@ public class VideoMessageCameraScreen: ViewController {
public init(
context: AccountContext,
updatedPresentationData: (initial: PresentationData, signal: Signal<PresentationData, NoError>)?,
peerId: EnginePeer.Id,
inputPanelFrame: CGRect,
allowLiveUpload: Bool,
completion: @escaping (EnqueueMessage?) -> Void
) {
self.context = context
self.updatedPresentationData = updatedPresentationData
self.inputPanelFrame = inputPanelFrame
self.allowLiveUpload = allowLiveUpload
self.allowLiveUpload = peerId.namespace != Namespaces.Peer.SecretChat
self.viewOnceAvailable = peerId.namespace == Namespaces.Peer.CloudUser
self.completion = completion
self.recordingStatus = RecordingStatus(micLevel: self.micLevelValue.get(), duration: self.durationValue.get())
@@ -1265,6 +1281,11 @@ public class VideoMessageCameraScreen: ViewController {
}
}
if duration < 1.0 {
self.completion(nil)
return
}
let finalDuration: Double
if let trimRange = self.node.previewState?.trimRange {
finalDuration = trimRange.upperBound - trimRange.lowerBound
@@ -1350,6 +1371,7 @@ public class VideoMessageCameraScreen: ViewController {
return true
}
fileprivate var recordingStartTime: Double?
fileprivate var scheduledLock = false
public func lockVideoRecording() {
if case .none = self.cameraState.recording {