Skip to content

Instantly share code, notes, and snippets.

View MuhammadjonTohirov's full-sized avatar

MTohir MuhammadjonTohirov

View GitHub Profile
@iAmrSalman
iAmrSalman / getVideoDuration.swift
Last active August 23, 2021 14:50
[Get video duration] function to get video duration #video
//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))