This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Don't forget to import AVFoundation | |
func getVideoDuration(from path: URL) -> String { | |
let asset = AVURLAsset(url: path) | |
let duration: CMTime = asset.duration | |
let totalSeconds = CMTimeGetSeconds(duration) | |
let hours = Int(totalSeconds / 3600) | |
let minutes = Int((totalSeconds.truncatingRemainder(dividingBy: 3600)) / 60) | |
let seconds = Int(totalSeconds.truncatingRemainder(dividingBy: 60)) |