Playing Youtube HD in Silverlight

Original author: Danny Park
  • Transfer
After reading Corey Schumann 's blog post about being able to play youtube videos in Silverlight, I decided to try to do it myself.

Here is a screenshot of the Asteroid Impact that plays in Silverlight 3 Video Player from the MSDN code gallery using the Youtube stream.
image
How did I get the video stream URL?

I’ll immediately make a reservation, I tried to get the URL on the client side, but the Youtube access policy forbids this. Then I acted differently, I created a WCF service that returns the URL we need.
  1. We do the HttpWebRequest to " www.youtube.com/get_video_info?video_id= " + videoID
  2. We read the answer and parsim. The returned response will be a string and look like a request.
    1. The necessary pieces of the answer that we need to parse are "token" and "fmt_map"
    2. The value of
      "fmt_map" will look something like "18/640000/9/0/115". The first number 18 or 22 means that the h.264 stream is available, there are other values, but we will omit them. If the first number is 6, then the stream cannot be lost, since it is a flash type that Silverlight does not support.
  3. We make the second HttpWebRequest to " www.youtube.com/get_video.php?video_id= " + videoID + "& t =" + token + "& fmt =" + fmt (it should be 18 or 22, depending on which one is available)
  4. In the response header, in the "Location" key, there will be a video stream URL
Now you can assign this URL to the source of the media item or media player and watch the video.

I would like to note that paragraph 4.C. under the terms of the agreement, youtube prohibits the receipt of video content in this way, this is just an experiment.

Also popular now: