Embedding A Video

Have you ever wondered how embedding those Flash widgets work on the web?

For example, you get some magic code from YouTube that makes a video show up on your website. If you actually look at the code, something really clever is going on there. In the src parameter, you normally include the path to a .swf file for embedding Flash content. In there is something that looks like a url to a page or folder like: http://www.youtube.com/v/123456

What’s pretty neat is that behind the scenes, a request to youtube gets made to that url. They have a rule setup (using apache mod_rewrite I would guess) that takes any request to the /v/ folder, and converts that request to something such as youtube.com/videos.php?id=123456. A script then runs, which talks to the database which has information about a video with that id number, and returns a url back with all of the appended information that the .swf could then read. Something like http://www.youtube.com/v/video.swf?title=great%20video&path=pathtovideo.flv etc.

All that happens in a few split seconds when the page embedding the video gets loaded. For an example check out what happens when you paste the path from the src parameter into your browser. Or check this link out and watch what happens in your browser url path: http://www.youtube.com/watch?v=8A11aqEKmTU