Exemple #1
0
        /////////////////////////////////////////////////////////////////////////
        //  Name: OnWebBrowserClosed
        //  Description: Called when the user closes the browser window.
        /////////////////////////////////////////////////////////////////////////
        void OnWebBrowserClosed()
        {
            ContentProtectionManager pManager;

            HResult hr = g_pPlayer.GetContentProtectionManager(out pManager);

            if (hr >= 0)
            {
                ContentProtectionManager.Enabler state = pManager.GetState();

                if (state != ContentProtectionManager.Enabler.Complete)
                {
                    Debug.WriteLine("User closed the browser window before we got the licence. Cancel.");
                    pManager.CancelEnable();
                }
            }
        }
Exemple #2
0
        /////////////////////////////////////////////////////////////////////////
        //  Name: OnContentEnablerMessage
        //  Description: Handles requests from the content protection manager.
        /////////////////////////////////////////////////////////////////////////
        void OnContentEnablerMessage()
        {
            ContentProtectionManager pManager;

            HResult hr = g_pPlayer.GetContentProtectionManager(out pManager);

            if (hr >= 0)
            {
                ContentProtectionManager.Enabler state = pManager.GetState();
                HResult hrStatus = pManager.GetStatus();   // Status of the last action.

                // EnablerState is a defined for this application; it is not a standard
                // Media Foundation enum. It specifies what action the
                // ContentProtectionManager helper object is requesting.

                try
                {
                    switch (state)
                    {
                    case ContentProtectionManager.Enabler.Ready:
                        // Start the enable action.
                        pManager.DoEnable(ContentProtectionManager.EnablerFlags.SilentOrNonSilent);
                        break;

                    case ContentProtectionManager.Enabler.SilentInProgress:
                        // We are currently in the middle of silent enable.

                        // If the status code is NS_E_DRM_LICENSE_NOTACQUIRED,
                        // we need to try non-silent enable.
                        if ((int)hrStatus == ContentProtectionManager.NS_E_DRM_LICENSE_NOTACQUIRED)
                        {
                            Debug.WriteLine("Silent enabler failed, attempting non-silent.");
                            pManager.DoEnable(ContentProtectionManager.EnablerFlags.ForceNonSilent);     // Try non-silent this time;
                        }
                        else
                        {
                            // Complete the operation. If it succeeded, the content will play.
                            // If it failed, the pipeline will queue an event with an error code.
                            pManager.CompleteEnable();
                        }
                        break;

                    case ContentProtectionManager.Enabler.NonSilentInProgress:
                        // We are currently in the middle of non-silent enable.
                        // Either we succeeded or an error occurred. Either way, complete
                        // the operation.
                        pManager.CompleteEnable();
                        break;

                    case ContentProtectionManager.Enabler.Complete:
                        // Nothing to do.
                        break;

                    default:
                        Debug.WriteLine(string.Format("Unknown EnablerState value! ({0})", state));
                        break;
                    }
                }
                catch
                {
                    // If a previous call to DoEnable() failed, complete the operation
                    // so that the pipeline will get the correct failure code.
                    pManager.CompleteEnable();
                }
            }
        }