This project has moved and is read-only. For the latest updates, please go here.

m3u8 and cookie

Nov 27, 2014 at 9:02 PM
I usually play video from a source in m3u8 and now the server have introduced measure of the user control. So I have analyze the new method of work this source and the first Request set a cookie and send the m3u8 list. And the next Request of player (in this case, your plugin) have to send the cookie in order to get the information.
Now, the versión that I use ( phonesm-45ee4449f092bacd4f5725b18bf8ddf2da3cdf7e) send the cookie as url-refered so I can't get the content.
So, Have the new versión this characteristic? Or How can I do in order to get this behavior in the versión that I use?
Thank you again.
Nov 28, 2014 at 10:03 AM
Adding cookies depends on which IWebReader you are using. The code you are using is from July, so you are probably using the one based on the portable HttpClient (unless you changed the default). If so, you need to use the same CookieContainer for both your initial request and for the requests from phonesm. The simplest way to do that is to get the cookie container to your version of InitializeMediaStream() (look for where "MediaStreamFacadeSettings.Parameters.Create()" is being called in your project) and pass it to phonesm through an HttpClientFactoryParameters instance. Something like this:
        _httpClientFactoryParameters = new HttpClientFactoryParameters { CookieContainer = your cookie container }
        void InitializeMediaStream()
            if (null != _mediaStreamFacade)

            _mediaStreamFacade = MediaStreamFacadeSettings.Parameters.Create();


            _mediaStreamFacade.StateChange += TsMediaManagerOnStateChange;
Note that some of the classes were renamed. If you don't have an "HttpClientFactoryParameters" class, then look for the old name: "HttpClientsParameters" (the CookieParameters stuff should be the same).

Come to think of it, the SimulatedPlayer console app uses the CookieContainer, so you can take a look there to see an example.

If that doesn't work, take a look with Fiddler or Wireshark to make sure the cookies are actually being sent. Sometimes the MS HttpClient is a bit finicky about what cookies should look like.
Nov 29, 2014 at 12:33 PM
Hi Henric,
Thanks you by your fast Reply. I can understand but I think that I haven't explained very well. The PlayerFramework uses your pluging, so I set the URI on the source parameter of the player. In the first Request of your pluging to the source, the server sends the cookie to your pluging and the following Request, your pluging use the cookie as url-refered.
In the case that I have to do other Request in order to get the cookie to set on your pluging, I have tried to do but I can't find it:
In the parameters there are Factory, Equals, GethashCode, gettype and toString. So I can't set the cookie.
Thank you again.
Nov 29, 2014 at 11:36 PM
SetParameters is an extension method for IMediaStreamFacadeBase. In the current source, it is in HttpClientFactoryExtenions.cs. With the code you are using, it is in SM.Media's Web subdirectory (IIRC). Regardless of where it is, it should look like this:
        public static void SetParameter(this IMediaStreamFacadeBase mediaStreamFacade, IHttpClientFactoryParameters httpClientFactoryParameters)
It is a helper that adds an instance of IHttpClientFactoryParameters to the Autofac DI container as a singleton, through the Autofac implementation for IBuilder.RegisterSingleton<>() in SM.Builder's BuilderBase:
        public void RegisterSingleton<TService>(TService instance)
            where TService : class

Where "ContainerBuilder" here is an instance of the Autofac ContainerBuilder class. The builder is then used by _mediaStreamFacade.CreateMediaStreamSourceAsync() to help create the MediaStreamSource.

If you add a cookie container through HttpClientFactoryParameters (not MediaStreamFacadeParameters), then it will be used by HttpClientFactory when creating HttpClient instances. If that cookie container has the cookie you need and if the portable HttpClient code feels like it, then it will be included as a cookie in phonesm's web requests.
Nov 30, 2014 at 12:34 PM
Hi Henric,
I will try implementing it this week.
Thank you again.