Partager via


How to supply Credentials to a Push Publishing Point using Expression Encoder v3 and v4

Well,  have you pushed content from Expression Encoder  to your server and got the "Access Denied" prompt lately?   Well, I have,  and so have a few other people.  Thanks to a request to look at such an issue and my colleague  Random on Windows Media    assistance we have a sample solution for you here.

Also note the changes below to make use of similar code for Microsoft Expression Encoder v4 Sp2

This programming sample is provided as - is for illustration only, without warranty either expressed or implied. The sample assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures.

INSTRUCTIONS:
Copy and paste the following code into your Microsoft Visual Studio 2008/2010 C# project, build the project, add the necessary Expression Encoder references.


C# CODE SAMPLE

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Security;

using Microsoft.Expression.Encoder;

using Microsoft.Expression.Encoder.Live;

namespace EEAuthenticate

{

    class EELiveAuthenticate

    {

        static void Main(string[] args)

        {

            if (args.Length != 2)

            {

                Console.Out.WriteLine("Usage: EEAuthenticate.exe <file_name> <server publishing point>");

                Console.Out.WriteLine("\nExample:");

                Console.Out.WriteLine(" EEAuthenticate.exe c:\\videos\\pinball.wmv https://streaming.contoso.com/live");

                return;

            }

            string fileToEncode = args[0];

            // To do: Validate that the file exists.

            string serverToPushTo = args[1];

            Console.Out.WriteLine("\nInitializing...\n");

            // Create a new LiveJob to begin broadcasting this file. Make sure

            // to dispose the LiveJob when you are finished with it.

            using (LiveJob job = new LiveJob())

            {

                // Create a new file source from the file name we were passed in

                LiveFileSource fileSource = job.AddFileSource(fileToEncode);

                // Set this source to Loop when finished

                fileSource.PlaybackMode = FileSourcePlaybackMode.Loop;

                // Make this source the active one

                job.ActivateSource(fileSource);

                // Setup event handlers

                job.AcquireCredentials += new EventHandler<AcquireCredentialsEventArgs>(job_AcquireCredentials);

                job.Status += new EventHandler<EncodeStatusEventArgs>(job_Status);

                // Set push properties

                Uri pubURL = new Uri(serverToPushTo);

                WindowsMediaPublishingPointOutputFormat pubpoint = new WindowsMediaPublishingPointOutputFormat();

                pubpoint.PublishingPoint = pubURL;

                job.OutputFormat = pubpoint;

  

                Console.Out.Write("\nEnter user name: ");

                _myUserName = Console.In.ReadLine();

                Console.Out.Write("\nEnter password: ");

                // The password cannot be a simple string; it must be a SecureString

                _pw = new SecureString();

                ConsoleKeyInfo cki;

                do

                {

                    cki = Console.ReadKey(true);

                    // Necessary to make sure we don't include the last Enter into the password

                    if (cki.Key != ConsoleKey.Enter)

                    {

                        _pw.AppendChar(cki.KeyChar);

                    }

                }

                while (cki.Key != ConsoleKey.Enter);

                // Start encoding

                Console.Out.Write("\nPress 'x' to stop encoding...\n");

                job.StartEncoding();

                // Let's listen for a keypress to know when to stop encoding

                while (Console.ReadKey(true).Key != ConsoleKey.X)

                {

                    // We are waiting for the 'x' key

                }

               

                // Stop our encoding

                Console.Out.WriteLine("Encoding stopped.");

                job.StopEncoding();

            }

        }

        static void job_Status(object sender, EncodeStatusEventArgs e)

        {

            Console.Out.WriteLine("\nStatus: " + e.Status.ToString());

        }

        static void job_AcquireCredentials(object sender, AcquireCredentialsEventArgs e)

        {

            e.UserName = _myUserName;

            e.Password = _pw;

            // Setting AcquireCredentialsMode to none is needed. However if you are

            // authenticating against a proxy, set this to Proxy.

            e.Modes = AcquireCredentialModes.None;

        }

        public static string _myUserName { get; set; }

        public static SecureString _pw { get; set; }

    }

}

 ===================================================================

Changes to code which allows its use with Expression Encoder v4

==================================================

See the 2 changes below to make the code work with version 4 go to the section that Set push properties and make the changes indicated below:

               // Set push properties

                Uri pubURL = new Uri(serverToPushTo);

Change #1 of 2

              Change From:

                 // EE3 version:
                // WindowsMediaPublishingPointOutputFormat pubpoint = new WindowsMediaPublishingPointOutputFormat();

             Change To:

                // EE4 version:
                PushBroadcastPublishFormat pubpoint = new PushBroadcastPublishFormat();

                pubpoint.PublishingPoint = pubURL;

Change #2 of 2

             Change From:

                // EE3 version:
                // job.OutputFormat = pubpoint;

             Change To:

                // EE4 version:
                job.PublishFormats.Add(pubpoint);

Also note that you can add a similar command line argument to the project debug properties

        Select Project | EEAuthenticate Propeties | Debug* | Start Project

        Select "Start Options"

        Enter the following in "Command line arguments:

             1, "<Drive>:\<media> " i.e. "D:\sampleMedia\pinball.wmv"
             2. https://<server>:<port>/push i.e. creates a push publishing point on the server

Comments

  • Anonymous
    September 07, 2011
    Thx! That was exactly what I was looking for!