/// <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();
        }
        /// <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);
            };
        }
Пример #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);
            };
        }
Пример #4
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();
        }
        /// <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); });
        }
        /// <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; });

        }
Пример #7
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();
                });
            }
        }
        /// <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();
                });
            }
        }