예제 #1
0
 internal void FireStateChanged(AudioSessionState NewState)
 {
     if (OnStateChanged != null)
     {
         OnStateChanged(this, NewState);
     }
 }
예제 #2
0
 // Fires on @out.Play() and @out.Stop()
 public void OnStateChanged(AudioSessionState state)
 {
     if (state == AudioSessionState.AudioSessionStateActive)
     {
         OnVolumeChanged(appVolume.SimpleAudioVolume.Volume, appVolume.SimpleAudioVolume.Mute);
     }
 }
예제 #3
0
 /// <summary>
 /// Retrieves the current state of the audio session.
 /// <seealso cref="SessionState"/>
 /// </summary>
 /// <param name="state">A variable into which the method writes the current session state.</param>
 /// <returns>HRESULT</returns>
 public unsafe int GetStateNative(out AudioSessionState state)
 {
     fixed(void *p = &state)
     {
         return(InteropCalls.CallI(UnsafeBasePtr, p, ((void **)(*(void **)UnsafeBasePtr))[3]));
     }
 }
        /// <summary>
        /// Notifies the client that the stream-activity state of the session has changed.
        /// </summary>
        /// <param name="state">The new session state.</param>
        /// <returns>An HRESULT code indicating whether the operation succeeded of failed.</returns>
        public int OnStateChanged(
            [In] AudioSessionState state)
        {
            audioSessionEventsHandler.OnStateChanged(state);

            return(0);
        }
예제 #5
0
 /// <summary>
 /// Notifies the client that the stream-activity state of the session has changed.
 /// </summary>
 /// <param name="newState">The new session state.</param>
 /// <returns>HRESULT</returns>
 int IAudioSessionEvents.OnStateChanged(AudioSessionState newState)
 {
     if (StateChanged != null)
     {
         StateChanged(this, new AudioSessionStateChangedEventArgs(newState));
     }
     return((int)Win32.HResult.S_OK);
 }
예제 #6
0
 private void SessionStateChanged(object sender, AudioSessionState newState)
 {
     if (newState == AudioSessionState.AudioSessionStateExpired)
     {
         session.Dispose();
         Dispatcher.Invoke(() => { MainWindow.instance.sessionControlStackPanel.Children.Remove(this); });
     }
 }
예제 #7
0
        void IAudioSessionEventsHandler.OnStateChanged(AudioSessionState state)
        {
            if (state != AudioSessionState.AudioSessionStateExpired)
            {
                return;
            }

            SessionEnded?.Invoke(this);
        }
        public int OnStateChanged(AudioSessionState newState)
        {
            if (newState == AudioSessionState.Expired)
            {
                this.SessionEnded?.Invoke();
            }

            return(0);
        }
예제 #9
0
        /// <summary>
        /// Notifies the client that the stream-activity state of the session has changed.
        /// </summary>
        /// <param name="newState">The new session state.</param>
        /// <returns>HRESULT</returns>
        void IAudioSessionEvents.OnStateChanged(AudioSessionState newState)
        {
            EventHandler <AudioSessionStateChangedEventArgs> handler = StateChanged;

            if (handler != null)
            {
                handler(this, new AudioSessionStateChangedEventArgs(newState));
            }
        }
예제 #10
0
 public int OnStateChanged(AudioSessionState NewState)
 {
     if (_sessionControl != null)
     {
         SessionStateChangedEventArgs e = new SessionStateChangedEventArgs(NewState);
         _sessionControl.FireStateChanged(e);
     }
     return(0);
 }
예제 #11
0
 private void SessionStateChanged(object sender, AudioSessionState newState)
 {
     if (newState == AudioSessionState.AudioSessionStateExpired)
     {
         session.Dispose();
         AudioMixerWindow.instance.SessionVolumeChanged(session, 0f, true);
         Dispatcher.Invoke(() => { AudioMixerWindow.instance.sessionStackPanel.Children.Remove(this); });
     }
 }
예제 #12
0
 public void OnStateChanged(AudioSessionState NewState)
 {
     // System.Diagnostics.Debug.WriteLine("STATE CHANGED. EVENT CLIENT");
     if (StateChanged != null)
     {
         StateChangedEventArgs oDisConnectSessionEventArgs = new StateChangedEventArgs(NewState);
         StateChanged(this, oDisConnectSessionEventArgs);
     }
 }
예제 #13
0
        /// <summary>
        /// Notifies the client that the stream-activity state of the session has changed.
        /// </summary>
        /// <param name="newState">The new session state.</param>
        /// <returns>HRESULT</returns>
        int IAudioSessionEvents.OnStateChanged(AudioSessionState newState)
        {
            EventHandler <AudioSessionStateChangedEventArgs> handler = this.StateChanged;

            if (handler != null)
            {
                handler(this, new AudioSessionStateChangedEventArgs(newState));
            }
            return((int)Win32.HResult.S_OK);
        }
예제 #14
0
        // Lists all devices, and for each device all processes that are currently playing sound using that device
        public static List <SoundInfoDevice> getSoundInfo()
        {
            List <SoundInfoDevice> soundInfoDevices = new List <SoundInfoDevice>();

            DeviceEnumerator    enumerator       = new DeviceEnumerator();
            IMMDeviceEnumerator deviceEnumerator = (IMMDeviceEnumerator)enumerator;
            IMMDeviceCollection deviceCollection = deviceEnumerator.EnumAudioEndpoints(EDataFlow.eRender, DeviceStatemask.DEVICE_STATE_ACTIVE);
            uint deviceCount = deviceCollection.GetCount();

            for (uint i = 0; i < deviceCount; i++)
            {
                SoundInfoDevice soundInfoDevice = new SoundInfoDevice();
                soundInfoDevices.Add(soundInfoDevice);

                IMMDevice device   = deviceCollection.Item(i);
                string    deviceId = device.GetId();
                soundInfoDevice.ID = deviceId;
                IMMPropertyStore propertyStore         = device.OpenPropertyStore(ProperyStoreMode.STGM_READ);
                PropertyKey      propertyKeyDeviceDesc = new PropertyKey();
                propertyKeyDeviceDesc.fmtid = new Guid(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0);
                propertyKeyDeviceDesc.pid   = 2;
                PropVariant deviceNamePtr = propertyStore.GetValue(ref propertyKeyDeviceDesc);
                string      deviceName    = Marshal.PtrToStringUni(deviceNamePtr.pszVal);
                soundInfoDevice.name = deviceName;

                Guid guidAudioSessionManager2             = new Guid("77AA99A0-1BD6-484F-8BC7-2C654C9A9B6F");
                IAudioSessionManager2 audioSessionManager = (IAudioSessionManager2)device.Activate(ref guidAudioSessionManager2, (int)ClsCtx.CLSCTX_ALL, IntPtr.Zero);


                IAudioSessionEnumerator sessionEnumerator = audioSessionManager.GetSessionEnumerator();

                int sessionCount = sessionEnumerator.GetCount();
                for (int j = 0; j < sessionCount; j++)
                {
                    IAudioSessionControl  audioSessionControl  = sessionEnumerator.GetSession(j);
                    IAudioSessionControl2 audioSessionControl2 = (IAudioSessionControl2)audioSessionControl;
                    AudioSessionState     state = audioSessionControl.GetState();
                    if (state == AudioSessionState.AudioSessionStateActive)
                    {
                        SoundInfoSession soundInfoSession = new SoundInfoSession();
                        soundInfoDevice.sessions.Add(soundInfoSession);

                        string displayName = audioSessionControl.GetDisplayName();
                        string iconPath    = audioSessionControl.GetIconPath();
                        int    processId   = audioSessionControl2.GetProcessId();
                        string processName = Process.GetProcessById(processId).MainWindowTitle;

                        soundInfoSession.pid        = processId;
                        soundInfoSession.windowName = processName;
                    }
                }
            }

            return(soundInfoDevices);
        }
예제 #15
0
 internal OSAudioApp(MMDevice device)
 {
     try
     {
         aev = device.AudioEndpointVolume;
     }
     catch (InvalidCastException)
     {
         Console.WriteLine("AudioEndpointVolume Error");
     }
     State = AudioSessionState.AudioSessionStateActive;
 }
예제 #16
0
        public void SessionStateChangedArgs_Sets_Session_State_Expired()
        {
            var mockAudioSession          = new Mock <IAudioSession>();
            const AudioSessionState state = AudioSessionState.Expired;

            var args = new SessionStateChangedArgs(mockAudioSession.Object, state);

            Assert.NotNull(args);
            Assert.NotNull(args.Session);
            Assert.Equal(mockAudioSession.Object, args.Session);

            Assert.Equal(state, args.State);
        }
예제 #17
0
        internal static EAudioSessionState AsEAudioSessionState(this AudioSessionState state)
        {
            switch (state)
            {
            case AudioSessionState.Inactive:
                return(EAudioSessionState.AudioSessionStateInactive);

            case AudioSessionState.Active:
                return(EAudioSessionState.AudioSessionStateActive);

            case AudioSessionState.Expired:
                return(EAudioSessionState.AudioSessionStateExpired);

            default:
                throw new ArgumentOutOfRangeException(nameof(state), state, null);
            }
        }
        public static string GetStringAudioState(AudioSessionState state)
        {
            switch (state)
            {
            case AudioSessionState.AudioSessionStateExpired:
                return("Expired");

            case AudioSessionState.AudioSessionStateActive:
                return("Active");

            case AudioSessionState.AudioSessionStateInactive:
                return("Inactive");

            default:
                return(string.Empty);
            }
        }
예제 #19
0
        public void MaybeRefreshSessions()
        {
            if (_shouldRefreshSessions)
            {
                _shouldRefreshSessions = false;
                _sessManager.RefreshSessions();

                int count = _sessManager.Sessions.Count;

                for (int i = 0; i < count; i++)
                {
                    AudioSessionControl session = _sessManager.Sessions[i];

                    if (session.GetProcessID == 0)
                    {
                        continue;
                    }

                    AudioSessionState state = session.State;

                    String fn = "";

                    try
                    {
                        Process p = Process.GetProcessById((int)(session.GetProcessID));
                        fn = p.ProcessName + ".exe";
                    }
                    catch (Exception e)
                    {
                        _logger.Error($"Could not get process name. {e.Message}", e);
                    }

                    if (state != AudioSessionState.AudioSessionStateExpired)
                    {
                        newSessionEvent(session, fn);

                        var stateStr = (state == AudioSessionState.AudioSessionStateActive) ? " (ACTIVE)" : "";
                        _logger.Info($"'{fn}' {session.GetProcessID} -- {session.AudioMeterInformation.MasterPeakValue + stateStr}");
                    }
                }
            }
        }
예제 #20
0
        private bool sessionIsActive(IAudioSessionEnumerator sessionEnumerator, int sessionIndex)
        {
            IAudioSessionControl sessionControl = null;

            try
            {
                sessionEnumerator.GetSession(sessionIndex, out sessionControl);
                AudioSessionState sessionState = AudioSessionState.AudioSessionStateInactive;
                sessionControl.GetState(out sessionState);

                return(sessionState == AudioSessionState.AudioSessionStateActive);
            }
            finally
            {
                if (sessionControl != null)
                {
                    Marshal.ReleaseComObject(sessionControl);
                }
            }
        }
예제 #21
0
        private void RefreshProperties()
        {
            if (_isDisposed)
            {
                return;
            }

            ComThread.Invoke(() =>
            {
                _isSystemSession = AudioSessionControl.IsSystemSoundsSession() == 0;
                AudioSessionControl.GetDisplayName(out _displayName);

                AudioSessionControl.GetIconPath(out _iconPath);

                EAudioSessionState state;
                AudioSessionControl.GetState(out state);
                _state = state.AsAudioSessionState();

                uint processId;
                AudioSessionControl.GetProcessId(out processId);
                _processId = (int)processId;

                AudioSessionControl.GetSessionIdentifier(out _id);

                try
                {
                    if (ProcessId > 0)
                    {
                        var proc         = Process.GetProcessById(ProcessId);
                        _executablePath  = proc.MainModule.FileName;
                        _fileDescription = proc.MainModule.FileVersionInfo.FileDescription;
                    }
                }
                catch
                {
                    _fileDescription = "";
                }
            });
        }
예제 #22
0
        private void Session_OnStateChanged(object sender, AudioSessionState newState)
        {
            AudioSessionControl2 senderSession  = (AudioSessionControl2)sender;
            AudioSession         changedSession = getAudioSessionObject(senderSession);

            if (Main.LOG_EVENTS)
            {
                Console.WriteLine(changedSession.ToString() + "\nState=" + newState.ToString());
            }

            if (newState == AudioSessionState.AudioSessionStateExpired)
            {
                expiredSessions.Add(changedSession.id);
            }
            else
            {
                if (expiredSessions.Contains(changedSession.id))
                {
                    expiredSessions.Remove(changedSession.id);
                }
            }
        }
예제 #23
0
 int IAudioSessionEvents.OnStateChanged(AudioSessionState newState)
 {
     return 0;
 }
예제 #24
0
 public int OnStateChanged(AudioSessionState NewState)
 {
     _Parent.FireStateChanged(NewState);
     return(0);
 }
예제 #25
0
 public int OnStateChanged(AudioSessionState NewState)
 {
     _Parent.FireStateChanged(NewState);
     return 0;
 }
 public AudioSessionStateChangedEventArgs(AudioSessionState newState)
 {
     NewState = newState;
 }
예제 #27
0
 /// <summary>
 /// Notifies the client that the stream-activity state of the session has changed.
 /// </summary>
 /// <param name="newState">The new session state.</param>
 /// <returns>HRESULT</returns>
 int IAudioSessionEvents.OnStateChanged(AudioSessionState newState)
 {
     if (StateChanged != null)
         StateChanged(this, new AudioSessionStateChangedEventArgs(newState));
     return (int) Win32.HResult.S_OK;
 }
 public HRESULT OnStateChanged(AudioSessionState NewState)
 {
     return(((delegate * unmanaged <IAudioSessionEvents *, AudioSessionState, int>)(lpVtbl[8]))((IAudioSessionEvents *)Unsafe.AsPointer(ref this), NewState));
 }
예제 #29
0
 public void FireStateChanged(AudioSessionState NewState)
 {
     OnStateChanged?.Invoke(this, NewState);
 }
예제 #30
0
 public SessionStateChangedEventArgs(AudioSessionState state)
 {
     State = state;
 }
예제 #31
0
 int IAudioSessionEvents.OnStateChanged(AudioSessionState state)
 {
     Debug.WriteLine(nameof(IAudioSessionEvents.OnStateChanged));
     return(0);
 }
예제 #32
0
 public void OnStateChanged(AudioSessionState state)
 {
 }
 internal void FireStateChanged(AudioSessionState NewState)
 {
     if (OnStateChanged != null) OnStateChanged(this, NewState);
 }
예제 #34
0
 /// <summary>
 /// Notifies the client that the stream-activity state of the session has changed.
 /// </summary>
 /// <param name="newState">The new session state.</param>
 /// <returns>HRESULT</returns>
 int IAudioSessionEvents.OnStateChanged(AudioSessionState newState)
 {
     EventHandler<AudioSessionStateChangedEventArgs> handler = this.StateChanged;
     if (handler != null)
         handler(this, new AudioSessionStateChangedEventArgs(newState));
     return (int) Win32.HResult.S_OK;
 }
예제 #35
0
 public int OnStateChanged(AudioSessionState NewState)
 {
     if (_sessionControl != null)
     {
         SessionStateChangedEventArgs e = new SessionStateChangedEventArgs(NewState);
         _sessionControl.FireStateChanged(e);
     }
     return 0;
 }
 public int OnStateChanged(AudioSessionState NewState)
 {
     return 0;
 }
예제 #37
0
 public SessionStateChangedEventArgs(AudioSessionState state)
 {
     State = state;
 }
예제 #38
0
 int IAudioSessionEvents.OnStateChanged(AudioSessionState newState)
 {
     return(0);
 }
예제 #39
0
 /// <summary>
 /// The GetState method retrieves the current state of the audio session.
 /// </summary>
 /// <returns>HRESULT</returns>
 public unsafe int GetStateNative(out AudioSessionState state)
 {
     fixed (void* p = &state)
     {
         return InteropCalls.CallI(_basePtr, p, ((void**)(*(void**)_basePtr))[3]);
     }
 }
예제 #40
0
 public AudioSessionStateChangedEventArgs(AudioSessionState newState)
 {
     NewState = newState;
 }
 /// <summary>
 /// Notifies the client that the stream-activity state of the session has changed.
 /// </summary>
 /// <param name="newState">The new session state.</param>
 /// <returns>HRESULT</returns>
 int IAudioSessionEvents.OnStateChanged(AudioSessionState newState)
 {
     StateChanged?.Invoke(this, new AudioSessionStateChangedEventArgs(newState));
     return(0);
 }