![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Let's say you want to embed some videos on your website, and you
want to put them in a list so people can click through and watch
them.
The title, description, and thumbnail you give to the video are
largely subjective decisions, but the duration - in minutes and
seconds - is an objective property of the media itself, which
means you should be able to extract it if you know the video's
URL. But how exactly do you do that?
Well, the first thing you'll need to do is figure out what
exactly you're dealing with: a raw video file (or stream) that
plays in the browser's <video> tag, or a link to a page
on a site like YouTube or Vimeo that hosts embeddable content.
Technologically speaking, it's an entirely different beast. A
YouTube page gives you the code for a player, and wraps all of it
up with copy protection and a variety of other features specific
to the platform. In other words, it's not handing the end user
something to play; it's playing it for them. It's kind of like the difference
between having a record of a song, and having a band come over with their
own instruments to play it on.
That doesn't mean they can't serve the same purpose
for the end user of your site, though, and in both cases it should
be possible to programmatically determine the duration of the
media. I've written a .NET library (ISchemm.DurationFinder)
that handles this for you for a variety of common video types with
just a URL; I'll walk through how it works overall, and how it
finds the duration for each type of media that it supports.