This project has moved. For the latest updates, please go here.

set header http when it is used with player framework

Aug 20, 2016 at 10:53 AM
Hi,
I need to set an header in order to access the live stream. it is used with player FrameWork as plugin and I don't know how I can set the header that plugin have to use. Could you help me?
Thanks
Coordinator
Aug 21, 2016 at 9:41 AM
Edited Aug 25, 2016 at 11:53 AM
If you are using the plugin, then you will need to modify the plugin itself. There didn't seem to be a clean way to make the plugin externally configurable, which is why the plugin is provided as source code even in the binary build.

The CreateMediaStreamFacade() method in StreamingMediaPlugin is probably the best place to do so.
        IMediaStreamFacade CreateMediaStreamFacade()
        {
            MediaStreamFacadeSettings.Parameters.UseHttpConnection = true;

            var mediaStreamFacade = MediaStreamFacadeSettings.Parameters.Create();

#if WINDOWS_APP || WINDOWS_PHONE_APP
            mediaStreamFacade.SetParameter(MediaManagerParameters);
#endif

            mediaStreamFacade.SetParameter(_metadataSink);

   [put customization here]

            return mediaStreamFacade;
        }
You will probably want to add something along the lines of,
      mediaStreamFacade.SetParameter(new WebReaderManagerParameters { DefaultHeaders =  new[] { new KeyValuePair(header, value) } } );
I haven't tried compiling that, but it should be close.

If that isn't enough, then pretty much everything can be customized using mediaStreamFacade.Builder.Register() and .RegisterSingleton().
Marked as answer by cansado2930 on 8/22/2016 at 2:06 PM
Aug 22, 2016 at 9:06 PM
Thanks Henric!! I think that it is enough because I only need to change the userAgent and add add other header (authentication). And Thanks for the example and for your good work!
Coordinator
Aug 25, 2016 at 12:12 PM
The user agent is normally derived from the app name by UserAgent, which can be overridden with:
using SM.Media.Web;
   ...
        sealed class SimpleUserAgent : IUserAgent
        {
            public string Name => "Some Name";
            public string Version => "1.2.3";

            private SimpleUserAgent()
            { }

            public static readonly IUserAgent Default = new SimpleUserAgent();
        }
   ...
        IMediaStreamFacade CreateMediaStreamFacade()
        {
           ...
            mediaStreamFacade.SetParameter(SimpleUserAgent.Default);
           ...
        }
One can take things one step further, but then the specifics depend on the HTTP stack that is in use. For HttpConnection, it could be something like:
using SM.Media.Web.HttpConnection;
   ...
        class SimpleUserAgentEncoder : IUserAgentEncoder
        {
            public string UsAsciiUserAgent { get; set; }
        }
   ...
        IMediaStreamFacade CreateMediaStreamFacade()
        {
           ...
            mediaStreamFacade.Builder.RegisterSingleton<IUserAgentEncoder>(new SimpleUserAgentEncoder { UsAsciiUserAgent = "blah/1.2.3" });
           ...
        }
Using the "DefaultHeaders" to set a user agent header will probably result in multiple user agent headers in the actual request.
Aug 26, 2016 at 9:42 PM
Very thanks!! I haven't thought about it, if it has multiple user agent is a problem in order to authenticate the player. I'm going to take your advice in order not to have this error. Thanks!