コード例 #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);
            }
        }
コード例 #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);
            }
        }
コード例 #3
0
        /// <summary>
        /// Unregisters the session from the service so events
        /// are not responded to anymore.
        /// </summary>
        /// <param name="sessionGroup"></param>
        private void UnregisterSessionGroup(IAudioSession sessionGroup)
        {
            sessionGroup.SessionEnded  -= OnSessionGroupEnded;
            sessionGroup.VolumeChanged -= OnSessionGroupVolumeChanged;
            if (_sessionGoups.Remove(sessionGroup.Id))
            {
                RaiseSessionRemoved(sessionGroup.Id);
            }

            sessionGroup.Dispose();
        }
コード例 #4
0
        /// <summary>
        /// Unregisters the session from the service so events
        /// are not responded to anymore.
        /// </summary>
        /// <param name="session">The audio session to unregister.</param>
        private void UnregisterSessionGroup(IAudioSession session)
        {
            //AppLogging.DebugLog(nameof(UnregisterSessionGroup), session.SessionIdentifier, session.DisplayName);
            session.SessionEnded  -= OnSessionGroupEnded;
            session.VolumeChanged -= OnSessionGroupVolumeChanged;
            if (_sessionGoups.Remove(session.Id))
            {
                RaiseSessionRemoved(session.Id);
            }

            session.Dispose();
        }
コード例 #5
0
        private void OnSessionEnded(IAudioSession session)
        {
            if (!_sessions.Remove(session.ID))
            {
                return;
            }

            session.SessionEnded  -= OnSessionEnded;
            session.VolumeChanged -= OnSessionVolumeChanged;
            session.Dispose();

            SessionEnded?.Invoke(session);
        }
コード例 #6
0
        private void OnSessionRemoved(IAudioSession session)
        {
            if (_devices.Remove(session.ID))
            {
                var deviceSession = session as AudioDevice;
                deviceSession.SessionCreated -= OnSessionCreated;
                deviceSession.SessionEnded   -= OnSessionRemoved;
                deviceSession.VolumeChanged  -= OnSessionVolumeChanged;
                session.Dispose();
            }

            RaiseSessionRemoved(session.ID);
        }
コード例 #7
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);
        }