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

前端 未结 6 1286
一整个雨季
一整个雨季 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条回答
  •  感动是毒
    2020-12-23 13:11

    Swift 4

    regardless of using didFinishPickingMediaWithInfo or didFinishRecordingToOutputFileAtURL you can:

    // needed only for didFinishPickingMediaWithInfo
    let outputFileURL = info[UIImagePickerControllerMediaURL] as! URL
    
    // get the asset
    let asset = AVURLAsset(url: outputFileURL)
    
    // get the time in seconds
    let durationInSeconds = asset.duration.seconds
    

提交回复
热议问题