Esempio n. 1
0
        /// <summary>
        /// Registers the session with the service so it's aware
        /// of events and they're handled properly.
        /// Sessions are always groupped regardless if they belong to a parent process or not.
        /// In the case that they don't have a parent process, the group will contain just one session.
        /// </summary>
        /// <param name="session">The audio session to register.</param>
        private void RegisterSession(IAudioSession session)
        {
            var groupId = GetSessionGroupId(session);

            if (_sessionGoups.TryGetValue(groupId, out var group))
            {
                var sessionGroup = group as AudioSessionGroup;
                if (!sessionGroup.ContainsSession(session))
                {
                    sessionGroup.AddSession(session);
                }
                else
                {
                    session.Dispose();
                }
            }
            else
            {
                var sessionGroup = new AudioSessionGroup(groupId, session.DisplayName);
                sessionGroup.AddSession(session);

                _sessionGoups.Add(groupId, sessionGroup);
                sessionGroup.SessionEnded  += OnSessionGroupEnded;
                sessionGroup.VolumeChanged += OnSessionGroupVolumeChanged;

                RaiseSessionCreated(groupId, sessionGroup.DisplayName, sessionGroup.Volume, sessionGroup.IsMuted);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Registers the session with the service so it's aware
        /// of events and they're handled properly.
        /// Sessions are always groupped regardless if they belong to a parent process or not.
        /// In the case that they don't have a parent process, the group will contain just one session.
        /// </summary>
        /// <param name="session">The audio session to register.</param>
        private void RegisterSession(IAudioSession session)
        {
            //AppLogging.DebugLog(nameof(RegisterSession), session.SessionIdentifier, session.DisplayName, session.Id.ToString());
            if (_sessionGoups.TryGetValue(session.Id, out var group))
            {
                var sessionGroup = group as AudioSessionGroup;
                if (!sessionGroup.ContainsSession(session))
                {
                    sessionGroup.AddSession(session);
                }
                else
                {
                    session.Dispose();
                }
            }
            else
            {
                var sessionGroup = new AudioSessionGroup(session.Id, session.DisplayName, session.IsDefault);
                sessionGroup.AddSession(session);

                _sessionGoups.Add(sessionGroup.Id, sessionGroup);
                sessionGroup.SessionEnded  += OnSessionGroupEnded;
                sessionGroup.VolumeChanged += OnSessionGroupVolumeChanged;

                RaiseSessionCreated(sessionGroup.Id, sessionGroup.DisplayName, sessionGroup.Volume, sessionGroup.IsMuted);
            }
        }
Esempio n. 3
0
        private void RegisterSession(IAudioSession session)
        {
            if (!_visibleSystemSounds && session.IsSystemSound)
            {
                session.Dispose();
                return;
            }

            var audioSession = session as AudioSession;
            var fileName     = audioSession.Process.GetMainModuleFileName(); // QUESTION: Should we use session.GroupingParam instead?

            // If we are able to grab the fileName for the process, group it with sessions from the same fileName
            if (!string.IsNullOrEmpty(fileName))
            {
                var groupID = fileName.GetHashCode();

                AudioSessionGroup sessionGroup;
                if (_sessions.TryGetValue(groupID, out var group))
                {
                    // We have a previously constrcuted group, so just add this session to that group and early out.
                    sessionGroup = group as AudioSessionGroup;
                    sessionGroup.AddSession(session);
                    return;
                }

                // Need to create a new group for this session and register it
                sessionGroup = new AudioSessionGroup(groupID, session.DisplayName);
                sessionGroup.AddSession(session);
                session = sessionGroup;
            }

            _sessions.Add(session.ID, session);
            session.SessionEnded  += OnSessionEnded;
            session.VolumeChanged += OnSessionVolumeChanged;

            SessionCreated?.Invoke(session);
        }