我有一个 iOS 相机应用程序,当用户开始按住一个按钮时,我想开始录制,并且在该 longTap 方法中能够知道录制当前持续了多长时间......在它结束之前。我想知道视频到现在为止的时长,或者换一种说法,用户已经录制了多长时间。
我的主要问题是如何在长按方法中知道用户录制了多长时间。因此,如果录音达到 X,它可以做 Y。
我目前尝试过:
视频录制的fileOutput方法中的以下内容(在用户让按钮后调用)
{
let videoRecorded = outputURL! as URL
let determineAsset = AVAsset(url: videoRecorded)
let determineCmTime = CMTime(value: determineAsset.duration.value, timescale: 600)
let secondsBruh = CMTimeGetSeconds(determineCmTime)
print(secondsBruh, "<--- seconds br8h")
if doNotRunPlayback == true {
print("DO NIT RUN PLAYBACK WAS TRUE")
} else {
print("here--- ", secondsBruh)
if secondsBruh <= 0.35 {
print("iiiiiiiiii")
isThisOverSeconds = true
photoOutput?.capturePhoto(with: AVCapturePhotoSettings(), delegate: self) //, put in the
} else {
isSettingThumbnail = false
playRecordedVideo(videoURL: videoRecorded)
}
}
}
确实开始录制我得到了视频的缩略图。你会看到一个 num 变量但忽略它......它总是会产生零,因为这是开始。
func fileOutput(_ output: AVCaptureFileOutput, didStartRecordingTo fileURL: URL, from connections: [AVCaptureConnection]) {
print("U IN THIS DIDSTARRECORD???")
isSettingThumbnail = true
photoOutput?.capturePhoto(with: AVCapturePhotoSettings(), delegate: self)
let testUrl = fileURL as URL!
let testAsset = AVAsset(url: testUrl!)
let deCmTime = CMTime(value: testAsset.duration.value, timescale: 600)
let seconds = CMTimeGetSeconds(deCmTime)
print(seconds, "<--- ok this si seconds")
num = Int(seconds)
print("723648732648732658723465872:::::", Int(seconds))
print("OUT THIS DIDSTART RECORD")
}
LongTap 方法
if sender.state == .ended {
print("UIGestureRecognizerStateEnded")
if num == 0 {
print("5555555555555")
photoOutput?.capturePhoto(with: AVCapturePhotoSettings(), delegate: self)
} else {
print("num was greater than 0")
}
stopRecording()
print("didLongTapEndedend")
} else if sender.state == .began {
print("UIGestureRecognizerStateBegan.")
startCapture()
print("didLongTapBeganend")
}
然而,我所拥有的是非常错误的。它几乎无法使用,绝对无法释放。
谢谢你的帮助。