📜 ⬆️ ⬇️

Playing Youtube HD in Silverlight

After reading a note on Cory Schumann 's blog about the possibility of playing youtube video in Silverlight, I decided to try it myself.

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

Immediately make a reservation, I tried to get the URL on the client side, but the Youtube access policy prohibits it. Then I acted differently, I created WCF sevis, which returns the URL we need.
  1. Making HttpWebRequest to " www.youtube.com/get_video_info?video_id= " + videoID
  2. We read the answer and parsim. The returned answer 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. Value
      "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 omit them. If the first number is 6, then the stream cannot be played, since it is a flash type that Silverlight does not support.
  3. Make the second HttpWebRequest to " www.youtube.com/get_video.php?video_id= " + videoID + "& t =" + token + "& fmt =" + fmt (must be 18 or 22, depending on which one is available)
  4. In the response header, in the "Location" key, the URL of the video stream will be
Now you can assign this URL to the source of the media element or media player and view the video.
')
I would like to note that paragraph 4.S. In terms of the agreement, youtube prohibits receiving video content in a way that is just an experiment.

Source: https://habr.com/ru/post/66614/


All Articles