iPhone :How to get duration of video selected from library?

前端 未结 6 1285
一整个雨季
一整个雨季 2020-12-23 12:14

I am using UIImagePickerController to choose video file from library. And user can upload the video.

Also I am using videoMaximumDuration p

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-23 13:01

    Swift 3.0 and Swift 4

    let outputFileURL = info[UIImagePickerControllerMediaURL] as! URL
    // get the asset
    let asset = AVURLAsset.init(url: outputFileURL) // AVURLAsset.init(url: outputFileURL as URL) in swift 3
    // get the time in seconds
    let durationInSeconds = asset.duration.seconds
    print("==== Duration is ",durationInSeconds)
    

提交回复
热议问题