×

Discussion Board

Results 1 to 3 of 3

Hybrid View

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    3

    WP8: Streaming video and audio from server with Basic Authentication

    Hello,

    I'm trying to figure out how to stream video and audio from a server over basic authentication. At least with displaying images over basic authentication I have to download the image first to IsolatedStorage and then open it from there, but this isn't a viable option because audio and video files are naturally bigger. I'm using the WebClient class to access the server with basic authentication with the login credentials in the WebClient's Header property. I don't suppose there's a way to get the stream with WebClient and send it to AudioPlayer/VideoPlayer?

  2. #2
    Nokia Developer Champion
    Join Date
    Jul 2012
    Posts
    88

    Re: WP8: Streaming video and audio from server with Basic Authentication

    Hello,
    What does your header credentials properties look like ? reading from a stored stream can be tricky and not memory efficient ...
    Have you tried something like :
    Code:
                UriBuilder stream = new UriBuilder();
                stream.Host = "stream host server";
                stream.UserName = "username";
                stream.Password = "password";
                stream.Path = "yourpath";
                stream.Port = 80;
    
                mediaelement.Source = stream.Uri;

  3. #3
    Registered User
    Join Date
    Oct 2012
    Posts
    3

    Re: WP8: Streaming video and audio from server with Basic Authentication

    Here's how the WebClient headers-property looks like:

    Code:
                client = new CookieWebClient();
                string username = "username";
                string password = "password";
                var token = Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format("{0}:{1}", username, password)));
                var authHeader = string.Format("Basic {0}", token);
    
                client.Headers["Authorization"] = authHeader;
    Oh, and I should explain: I'm using an extended version of the WebClient class because the connection didn't otherwise work. The extended class basically handles cookies better, and it's made following this post: http://firebelly.net/post/3341374382...client-for-wp7

    And yes, I just tried the UriBuilder but the MediaElement page is blank so I guess the video couldn't be accessed.

    I'm not 100% sure I used the UriBuilder correctly though. Heres my code:

    Code:
                Uri site = new Uri("https://server.somesite.com/ba/php/download.php?url=" + videoFileID);
                UriBuilder stream = new UriBuilder(site);
                stream.UserName = "username";
                stream.Password = "password";
    
                MediaElement videoPlayer = new MediaElement();
                videoPlayer.Source = stream.Uri;
                videoPlayer.AutoPlay = true;
    
                LayoutRoot.Children.Add(videoPlayer);
    
                videoPlayer.Play();
    Is it known that you can access Basic Authentication server files with UriBuilder?

    A colleague is doing a same kind of application for this service on Android and he told me he had to do some kind of double buffering by downloading the video to phone memory and streaming it from there. I'm not completely sure what this means but maybe it can help with this matter. And if I did download the video to the phone storage I would also have to figure out a way to delete it after the user no longer plays the file.

Similar Threads

  1. Replies: 1
    Last Post: 2009-02-19, 13:53
  2. Replies: 0
    Last Post: 2008-09-25, 06:39

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×