// 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();
     });
 }
 /// 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();
         });
     }
 }
示例#3
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();
                });
            }
        }