Ejemplo n.º 1
0
        /// <summary>
        /// The helper class will determine the exact type of ServiceRequest in order to customize and send
        /// the service request. ServiceRequests (except for Individualization and Revocation) also support the
        /// GenerateManualEnablingChallenge method. This can be used to read and customize the SOAP challenge
        /// and manually send the challenge.
        /// </summary>
        void ProcessServiceRequest(IMediaProtectionServiceRequest serviceRequest)
        {
            //Alternatively the serviceRequest can be determined by the Guid serviceRequest.Type
            if (serviceRequest is PlayReadyIndividualizationServiceRequest)
            {
                PlayReadyHelpers.ReactiveIndividualization(serviceRequest as PlayReadyIndividualizationServiceRequest, serviceCompletionNotifier, () => PlayReadyInfo.RefreshStatics());
                PlayReadyInfo.RefreshStatics();
            }
            else if (serviceRequest is PlayReadyLicenseAcquisitionServiceRequest)
            {
                var licenseRequest = serviceRequest as PlayReadyLicenseAcquisitionServiceRequest;
                // The inital service request url was taken from the playready header from the dash manifest.
                // This can overridden to a different license service prior to sending the request (staging, production,...).
                licenseRequest.Uri = new Uri(licenseURL);

                PlayReadyHelpers.ReactiveLicenseAcquisition(licenseRequest, serviceCompletionNotifier);
                SetPlaybackEnabled(true);
            }

            // Here are the additional service calls available to support other scenarios
            //PlayReadySecureStopServiceRequest
            //PlayReadyDomainJoinServiceRequest
            //PlayReadyDomainLeaveServiceRequest
            //PlayReadyMeteringReportServiceRequest

            //PlayReadyRevocationServiceRequest
        }
Ejemplo n.º 2
0
        /// <summary>
        /// A view model class for the IndivReactive Scenario.
        /// </summary>
        public ProactiveViewModel(MediaElement mediaElement)
        {
            /// The ProtectionManager provides communication between the player and PlayReady DRM.
            /// The helper class will configure the protection manager for PlayReady and assign an
            /// event handler for Service requests.
            this.ProtectionManager         = PlayReadyHelpers.InitializeProtectionManager(ServiceRequested);
            mediaElement.ProtectionManager = this.ProtectionManager;
            /// The PlayReadyInfoViewModel is used in this sample app to show PlayReadyStatistics such as
            /// SecurityLevel and hardware support within the UI.
            PlayReadyInfo = new PlayReadyInfoViewModel();
            PlayReadyInfo.RefreshStatics();

            mediaElement.CurrentStateChanged += (s, a) => {
                ViewModelBase.Log("Media State::" + mediaElement.CurrentState);
            };

            mediaElement.MediaFailed += (s, a) => {
                ViewModelBase.Log("Media Failed::" + a.ErrorMessage);
            };

            /// Proactive license acqusition will ensure a license is available
            /// prior to playback
            CmdGetLicense = new RelayCommand(() => { GetLicense(new Guid(this.KeyId)); }, () => { return(PlayReadyHelpers.IsIndividualized); });

            /// Play is enabled once a license is available
            CmdPlayMovie = new RelayCommand(() => { mediaElement.Source = new Uri(moviePath); SetPlaybackEnabled(true); },
                                            () => IsLicenseAvailable(new Guid(KeyId)));
            CmdStopMovie = new RelayCommand(() => { mediaElement.Stop(); SetPlaybackEnabled(false); },
                                            () => IsLicenseAvailable(new Guid(KeyId)));

            /// Proactive individualization will ensure PlayReady have been configured
            /// to begin making license requests
            IndividualizeIfNeeded();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// A view model class for the ReactiveRequest Scenario.
        /// The ViewModel takes a UI MediaElement in the contructor to wire up commands and events to simplify the sample.
        /// Decoupling the MediaElement from the ViewModel would require addtional MVVM infrastucture.
        /// </summary>
        public ReactiveViewModel(MediaElement mediaElement)
        {
            /// The ProtectionManager provides communication between the player and PlayReady DRM.
            /// The helper class will configure the protection manager for PlayReady and assign an
            /// event handler for Service requests.
            this.ProtectionManager         = PlayReadyHelpers.InitializeProtectionManager(ServiceRequested);
            mediaElement.ProtectionManager = this.ProtectionManager;
            /// The PlayReadyInfoViewModel is used in this sample app to show PlayReadyStatistics such as
            /// SecurityLevel and hardware support in the UI.
            PlayReadyInfo = new PlayReadyInfoViewModel();
            PlayReadyInfo.RefreshStatics();

            /// Reactive license acqusition will happen automatically when setting the source of
            /// a MediaElement to protected content.
            CmdPlayMovie = new RelayCommand(() => { mediaElement.Source = new Uri(moviePath); SetPlaybackEnabled(true); });
            /// The licenseUrl in the sample is set to return a non-peristent license. When there is a
            /// hard Stop() on the playback, a new license will be requested on Play().
            CmdStopMovie = new RelayCommand(() => { mediaElement.Stop(); SetPlaybackEnabled(false); });

            mediaElement.CurrentStateChanged += (s, a) => {
                ViewModelBase.Log("Media State::" + mediaElement.CurrentState);
            };

            mediaElement.MediaFailed += (s, a) => {
                ViewModelBase.Log("Err::" + a.ErrorMessage);
            };
        }
 // Proactive individualization is used to configure playready to the selected
 // hardware/software mode
 void Individualize()
 {
     PlayReadyHelpers.ProactiveIndividualization(() => {
         modeSelected = true;
         CmdPlayMovie.RaiseCanExecuteChanged();
         CmdUseHardware.RaiseCanExecuteChanged();
         CmdUseSoftware.RaiseCanExecuteChanged();
     });
 }
Ejemplo n.º 5
0
 void RenewActiveLicense()
 {
     if (activePlayReadyHeader != null)
     {
         var licenseServiceRequest = licenseSession.CreateLAServiceRequest();
         licenseServiceRequest.ContentHeader = activePlayReadyHeader;
         licenseServiceRequest.Uri           = new Uri(licenseUrl);
         PlayReadyHelpers.ReactiveLicenseAcquisition(licenseServiceRequest, null);
     }
 }
Ejemplo n.º 6
0
 /// A check is made to see of the device has been initialize and a indiv
 /// service request is sent if not. The callback will notify the app license
 /// calls can now be made.
 void IndividualizeIfNeeded()
 {
     if (!PlayReadyHelpers.IsIndividualized)
     {
         PlayReadyHelpers.ProactiveIndividualization(() => {
             CmdGetLicense.RaiseCanExecuteChanged();
             PlayReadyInfo.RefreshStatics();
         });
     }
 }
Ejemplo n.º 7
0
        /// A content header is required to make a proactive license request.
        /// The header needs at minimum a KeyId and a License URL.
        /// Additionally you set a custom data property which will be passed in the signed
        /// section of the license request for use by the service.
        void GetLicense(Guid kid)
        {
            var laURL         = new Uri(licenseUrl);
            var customData    = "token:12345";
            var contentHeader = new PlayReadyContentHeader(kid, "", PlayReadyEncryptionAlgorithm.Aes128Ctr, laURL, laURL, customData, Guid.Empty);

            PlayReadyHelpers.ProactiveLicenseAcquisition(contentHeader, () => {
                CmdPlayMovie.RaiseCanExecuteChanged();
                CmdStopMovie.RaiseCanExecuteChanged();
            });
        }
Ejemplo n.º 8
0
 void ProcessServiceRequest(IMediaProtectionServiceRequest serviceRequest)
 {
     //Alternatively the serviceRequest can be determined by the Guid serviceRequest.Type
     if (serviceRequest is PlayReadyIndividualizationServiceRequest)
     {
         PlayReadyHelpers.ReactiveIndividualization(serviceRequest as PlayReadyIndividualizationServiceRequest, serviceCompletionNotifier, () => PlayReadyInfo.RefreshStatics());
         PlayReadyInfo.RefreshStatics();
     }
     else if (serviceRequest is PlayReadyLicenseAcquisitionServiceRequest)
     {
         PlayReadyHelpers.ReactiveLicenseAcquisition(serviceRequest as PlayReadyLicenseAcquisitionServiceRequest, serviceCompletionNotifier);
     }
 }
        /// <summary>
        /// The helper class will determine the exact type of ServiceRequest in order to customize and send
        /// the service request. ServiceRequests (except for Individualization and Revocation) also support the
        /// GenerateManualEnablingChallenge method. This can be used to read and customize the SOAP challenge
        /// and manually send the challenge.
        /// </summary>
        void ProcessServiceRequest(IMediaProtectionServiceRequest serviceRequest)
        {
            //Alternatively the serviceRequest can be determined by the Guid serviceRequest.Type
            if (serviceRequest is PlayReadyIndividualizationServiceRequest)
            {
                PlayReadyHelpers.ReactiveIndividualization(serviceRequest as PlayReadyIndividualizationServiceRequest, serviceCompletionNotifier, () => PlayReadyInfo.RefreshStatics());
                PlayReadyInfo.RefreshStatics();
            }
            else if (serviceRequest is PlayReadyLicenseAcquisitionServiceRequest)
            {
                var licenseRequest = serviceRequest as PlayReadyLicenseAcquisitionServiceRequest;
                // The initial service request url was taken from the playready header from the dash manifest.
                // This can overridden to a different license service prior to sending the request (staging, production,...).
                licenseRequest.Uri = new Uri(licenseUrl);

                PlayReadyHelpers.ReactiveLicenseAcquisition(licenseRequest, serviceCompletionNotifier);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// ...
        /// </summary>
        void ProcessServiceRequest(IMediaProtectionServiceRequest serviceRequest)
        {
            //Alternatively the serviceRequest can be determined by the Guid serviceRequest.Type
            if (serviceRequest is PlayReadyIndividualizationServiceRequest)
            {
                PlayReadyHelpers.ReactiveIndividualization(serviceRequest as PlayReadyIndividualizationServiceRequest, serviceCompletionNotifier, () => PlayReadyInfo.RefreshStatics());
                PlayReadyInfo.RefreshStatics();
            }
            else if (serviceRequest is PlayReadyLicenseAcquisitionServiceRequest)
            {
                var licenseServiceRequestNotUsed = (serviceRequest as PlayReadyLicenseAcquisitionServiceRequest);
                activePlayReadyHeader = licenseServiceRequestNotUsed.ContentHeader;

                var licenseServiceRequest = licenseSession.CreateLAServiceRequest();
                licenseServiceRequest.ContentHeader = activePlayReadyHeader;
                licenseServiceRequest.Uri           = new Uri(licenseUrl);
                PlayReadyHelpers.ReactiveLicenseAcquisition(licenseServiceRequest, serviceCompletionNotifier);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// A view model class for the IndivReactive Scenario.
        /// </summary>
        public HardwareDRMViewModel(MediaElement mediaElement)
        {
            this.ProtectionManager         = PlayReadyHelpers.InitializeProtectionManager(ServiceRequested);
            mediaElement.ProtectionManager = this.ProtectionManager;
            PlayReadyInfo = new PlayReadyInfoViewModel();
            PlayReadyInfo.RefreshStatics();

            mediaElement.CurrentStateChanged += (s, a) => {
                ViewModelBase.Log("Media State::" + mediaElement.CurrentState);
            };

            mediaElement.MediaFailed += (s, a) => {
                ViewModelBase.Log("Media Failed::" + a.ErrorMessage);
            };

            CmdPlayMovie = new RelayCommand(() => { mediaElement.Source = new Uri(moviePath); SetPlaybackEnabled(true); },
                                            () => { return(modeSelected && PlayReadyHelpers.IsIndividualized); });
            CmdStopMovie   = new RelayCommand(() => { mediaElement.Stop(); SetPlaybackEnabled(false); });
            CmdUseHardware = new RelayCommand(() => { ConfigureHardwareDRM(mediaElement); },
                                              () => { return(!modeSelected); });
            CmdUseSoftware = new RelayCommand(() => { ConfigureSoftwareDRM(mediaElement); },
                                              () => { return(!modeSelected); });
        }
Ejemplo n.º 12
0
        /// <summary>
        /// A view model class for the IndivReactive Scenario.
        /// </summary>
        public SecureStopViewModel(MediaElement mediaElement)
        {
            this.ProtectionManager         = PlayReadyHelpers.InitializeProtectionManager(ServiceRequested);
            mediaElement.ProtectionManager = this.ProtectionManager;

            licenseSession = PlayReadyHelpers.createLicenseSession();
            licenseSession.ConfigureMediaProtectionManager(mediaElement.ProtectionManager);

            PlayReadyInfo = new PlayReadyInfoViewModel();
            PlayReadyInfo.RefreshStatics();

            CmdPlayMovie = new RelayCommand(
                () => { mediaElement.Source = new Uri(moviePath); SetPlaybackEnabled(true); },
                () => publisherCert != null);

            CmdStopMovie = new RelayCommand(() => { mediaElement.Stop(); },
                                            () => publisherCert != null);

            CmdGetPublisherCert = new RelayCommand(() =>
            {
                GetPublisherCert(publisherID, (cert) =>
                {
                    CmdPlayMovie.RaiseCanExecuteChanged();
                    CmdStopMovie.RaiseCanExecuteChanged();
                    CmdRenewLicense.RaiseCanExecuteChanged();
                });
            });

            CmdRenewLicense = new RelayCommand(() => RenewActiveLicense(),
                                               () => publisherCert != null);

            mediaElement.CurrentStateChanged += (s, a) =>
            {
                ViewModelBase.Log("Media State::" + mediaElement.CurrentState);

                switch (mediaElement.CurrentState)
                {
                case MediaElementState.Closed:
                    SendSecureStopRecords();
                    activePlayReadyHeader = null;
                    SetPlaybackEnabled(false);
                    // renewing the licenseSession for subsequent Plays since the
                    // session is stopped
                    licenseSession = PlayReadyHelpers.createLicenseSession();
                    licenseSession.ConfigureMediaProtectionManager(mediaElement.ProtectionManager);
                    break;

                default:
                    break;
                }
            };

            mediaElement.MediaFailed += (s, a) =>
            {
                ViewModelBase.Log("Err::" + a.ErrorMessage);
            };

            var localSettings = ApplicationData.Current.LocalSettings;
            ApplicationDataContainer container;

            localSettings.Containers.TryGetValue("PublisherCerts", out container);
            if (container != null && container.Values.ContainsKey(publisherID))
            {
                publisherCert = (byte[])container.Values[publisherID];
            }

            try
            {
                var securityVersion = PlayReadyStatics.PlayReadySecurityVersion;
                SendSecureStopRecords();
            }
            catch {
                PlayReadyHelpers.ProactiveIndividualization(() =>
                {
                    PlayReadyInfo.RefreshStatics();
                });
            }
        }