예제 #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();
            }
        }
예제 #2
0
 //TODO: this does not trigger
 private static void SmtcManagerOnCurrentSessionChanged(GlobalSystemMediaTransportControlsSessionManager sender, CurrentSessionChangedEventArgs args)
 {
     if (_smtc != null)
     {
         _smtc.MediaPropertiesChanged    -= SmtcOnMediaPropertiesChanged;
         _smtc.TimelinePropertiesChanged -= SmtcOnTimelinePropertiesChanged;
     }
     _smtc = sender.GetCurrentSession();
     if (_smtc != null)
     {
         _smtc.MediaPropertiesChanged += SmtcOnMediaPropertiesChanged;
         _mediaProperties              = _smtc.TryGetMediaPropertiesAsync().GetAwaiter().GetResult();
     }
 }
        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();
        }
예제 #4
0
 //TODO: This does not trigger
 private static void SmtcManagerOnSessionsChanged(GlobalSystemMediaTransportControlsSessionManager sender, SessionsChangedEventArgs args)
 {
     Console.WriteLine("Changed");
 }