public void StartListening()
 {
     _messageDisplayer.OutputMessage("Start listening");
     _cancellationTokenSource?.Cancel();
     _cancellationTokenSource = new CancellationTokenSource();
     _analyst = Repeat.Interval(
         _checkInterval,
         () => AnalyseSpotifyStatus(_cancellationTokenSource.Token),
         _cancellationTokenSource.Token);
 }
Example #2
0
        private bool IsOutputingSound(string limitToProcess = null)
        {
            using (var sessionManager = GetDefaultAudioSessionManager2(DataFlow.Render))
            {
                using (var sessionEnumerator = sessionManager.GetSessionEnumerator())
                {
                    foreach (var session in sessionEnumerator)
                    {
                        try
                        {
                            using (var audioMeterInformation = session.QueryInterface <AudioMeterInformation>())
                                using (var session2 = session.QueryInterface <AudioSessionControl2>())
                                {
                                    if (limitToProcess != null)
                                    {
                                        var processId = session2.ProcessID;
                                        var name      = Process.GetProcessById(processId).ProcessName;
                                        if (name != limitToProcess)
                                        {
                                            continue;
                                        }
                                    }

                                    var peakValue = Math.Abs(audioMeterInformation.GetPeakValue());
                                    if (peakValue > 6E-9)
                                    {
                                        return(true);
                                    }
                                }
                        }
                        catch (Exception e)
                        {
                            _messageDisplayer.OutputMessage("Exception: " + e.Message + " at " + e.StackTrace);
                        }
                    }
                }
            }
            return(false);
        }