首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何访问当前录制的视频的长度?

如何访问当前录制的视频的长度?
EN

Stack Overflow用户
提问于 2018-12-26 22:04:27
回答 2查看 208关注 0票数 0

我有一个iOS相机应用程序,当用户开始按住按钮时,我想要开始录制,并且在该longTap方法中能够知道记录当前的时间。在它结束之前。我想知道视频到现在为止有多长时间,或者用不同的方式来描述,,用户已经为录制了多长时间。

我的主要问题是如何知道,在长按压方法中,用户已经录制了多长时间。所以,如果录音已经达到X,它可以做Y。

我目前已尝试:

用于视频记录的fileOutput方法中的以下内容(在用户已让其用于按钮后调用)

代码语言:javascript
复制
{

        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)
            }
        }
    }

开始录音了我得到了视频的缩略图。你会看到一个数值变量但忽略它..。考虑到这是个开始,它总是会产生零。

代码语言:javascript
复制
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法

代码语言:javascript
复制
        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")

    }

然而,我所拥有的却是非常多才多艺。它几乎是不可用的,绝对无法发布。

谢谢你的帮助。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-12-27 00:41:48

使用UIControlEvents.touchDown & UIControlEvents.touchUpInside事件。尝尝这个。

代码语言:javascript
复制
import UIKit
import PlaygroundSupport

class MyViewController : UIViewController {

    var timer:Timer!

    override func loadView() {
        let view = UIView()


        let btn = UIButton.init(frame: CGRect(x: 150, y: 200, width: 200, height: 20))
        btn.setTitle("Record/Capture", for: UIControlState.normal)
        btn.clipsToBounds
        btn.backgroundColor = UIColor.red
        view.addSubview(btn)
        self.view = view

        btn.addTarget(self, action: #selector(touchDown(_:)), for: UIControlEvents.touchDown)
        btn.addTarget(self, action: #selector(touchUpInside(_:)), for: UIControlEvents.touchUpInside)

    }

   @objc func touchDown(_ sender:UIButton) {
    timer = Timer.scheduledTimer(withTimeInterval: TimeInterval.init(3), repeats: false, block: { (timer) in
        self.startRecording()
    })
}

    @objc func touchUpInside(_ sender:UIButton) {
        if timer.isValid {
            self.capturePhoto()
        } else {
            self.stopRecording()
        }
        timer.invalidate()
    }

    func startRecording() {
        // Recording
        print("Start Recording")
        timer.invalidate()
    }

    func stopRecording() {
        // stopRecording
        print("Stop Recording")

    }

    func capturePhoto() {
        print("Capture Photo")
    }
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = MyViewController()
票数 0
EN

Stack Overflow用户

发布于 2018-12-27 02:05:21

别看录像。看看钟。

你知道录音是什么时候开始的因为是你开始的。你知道现在几点了。减去。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53937650

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档