Problem with video download using GetVideoUri

Nov 8, 2012 at 6:44 PM
Edited Nov 8, 2012 at 7:10 PM

Hi

I'm trying to use Youtube.GetVideoUri directly in my app to download youtube videos using a WebClient, but I'm getting some exceptions thrown when I start the download.

My code is something like this:

 

YouTube.GetVideoUri(YoutubeVideoId, YouTubeQuality.Quality720P, (entry, excep) =>
      {
          if (excep != null)
          {
              //this is not the place where I get exceptions
          }
          else
          {
              if (entry != null)
              {
                  Debug.WriteLine(entry.Uri.AbsoluteUri);
		  //here starts the download
		  webClient.OpenReadAsync(entry.Uri);
              }
          }
      });

 

This code is similar to YouTube.Play, and I'm getting the Uri just fine through the Debug. But when the download starts, I get System.IO.FileNotFoundException and System.UnauthorizedAccessException. The thing is: this Uri is the same when you Debug the Uri inside Youtube.Play, and it works inside there with the MediaPlayerLauncher, but not in my code. Does anybody know what I could be missing when using the GetVideoUri response? Thanks.

Coordinator
Nov 9, 2012 at 11:46 AM

In Silverlight you cannot download files from URIs which are not in your domain.

See http://msdn.microsoft.com/en-us/library/cc645032%28v=vs.95%29.aspx

Nov 9, 2012 at 2:57 PM

Thanks for the reply, rsuter. Actually, I found another way to download the Uri provided by GetVideoUri. Now I'm using HttpWebRequest instead of WebClient, and it works fine.

Anyway, maybe these security restrictions can be a barrier to my certification process in Dev Center, it surely is a worth reading.

Coordinator
Nov 9, 2012 at 2:59 PM

The problem is only with Silverlight "Web" applications. I think in Windows Phone you won't get a problem... You can also use the MyToolkit's http classes: http://mytoolkit.codeplex.com/wikipage?title=Http