示例#1
0
        public static void Reload()
        {
            if (_smtcManager != null)
            {
                _smtcManager.CurrentSessionChanged -= SmtcManagerOnCurrentSessionChanged;
                _smtcManager.SessionsChanged       -= SmtcManagerOnSessionsChanged;
            }

            if (_smtc != null)
            {
                _smtc.MediaPropertiesChanged    -= SmtcOnMediaPropertiesChanged;
                _smtc.TimelinePropertiesChanged -= SmtcOnTimelinePropertiesChanged;
            }

            //TODO: Implement automatic switching to new playing smtc

            _smtcManager = GlobalSystemMediaTransportControlsSessionManager.RequestAsync().GetAwaiter().GetResult();
            _smtcManager.SessionsChanged       += SmtcManagerOnSessionsChanged;
            _smtcManager.CurrentSessionChanged += SmtcManagerOnCurrentSessionChanged;
            _smtc = _smtcManager.GetCurrentSession();
            if (_smtc != null)
            {
                _smtc.MediaPropertiesChanged    += SmtcOnMediaPropertiesChanged;
                _smtc.TimelinePropertiesChanged += SmtcOnTimelinePropertiesChanged;
                _mediaProperties = _smtc.TryGetMediaPropertiesAsync().GetAwaiter().GetResult();
                UpdateMediaProperties();
            }
        }
        public override void Activate()
        {
            if (IsActive)
            {
                throw new InvalidOperationException("Hook is already active.");
            }

            Logger.Hook.LogDebug("Activated");

            IsActive = true;

            // awaiting here hangs the app?
            manager = Manager.RequestAsync().AsTask().GetAwaiter().GetResult();

            SetupHook();
            TryHook();
        }