Manii Lagah
Manii Lagah

Reputation: 1

find duration of video using url in swift

I have url of a video. I want to know the duration of it without playing it.

I tried this:

let data = "http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4"
let a = NSURL(string: data)
let asset = AVAsset(URL: a!)

let duration = asset.duration
let durationTime = CMTimeGetSeconds(duration)

print("the duration is",durationTime)

Upvotes: 0

Views: 4465

Answers (1)

Abhirajsinh Thakore
Abhirajsinh Thakore

Reputation: 1822

You can use like this if the video is picked form picker

        let asset = AVURLAsset(url: video)
        let durationInSeconds = asset.duration.seconds
        print(durationInSeconds)

Upvotes: 2

Related Questions