Exemplo n.º 1
0
 // Check if there is any other sound playing except the defaulsession
 public bool IsAwkward(AudioSession defaultSession, float tolerance)
 {
     tolerance *= tolerance;
     if (tolerance < 1) tolerance = 1;
     using (var sessionManager = GetDefaultAudioSessionManager2(DataFlow.Render))
     {
         using (var sessionEnumerator = sessionManager.GetSessionEnumerator())
         {
             foreach (var session in sessionEnumerator)
             {
                 if(session.GroupingParam != defaultSession.groupingParam)
                 {
                     using (var audioMeterInformation = session.QueryInterface<AudioMeterInformation>())
                     {
                         if (audioMeterInformation.PeakValue > tolerance / 1000)
                         {
                             return false;
                         }
                     }
                 }
             }
         }
     }
     return true;
 }
Exemplo n.º 2
0
 // Start monitoring the selected sound session
 private void startBtn_Click(object sender, EventArgs e)
 {
     if (sourceListBox.CheckedItems.Count > 0)
        {
        string sessionName = sourceListBox.CheckedItems[0].ToString();
        foreach (var session in sessionList_)
        {
            if (session.name.Equals(sessionName))
            {
                defaultSession_ = session;
                timer1.Start();
                logTextBox.Text = "Start";
                splitContainer.Panel1.Enabled = false;
                splitContainer.Panel1.BackColor = colorDisabled_;
                groupBox1.Enabled = false;
                groupBox1.BackColor = colorDisabled_;
                startBtn.Enabled = false;
                stopBtn.Enabled = true;
                break;
            }
        }
        }
 }
Exemplo n.º 3
0
 // Check if a given session currently is play audio
 public bool SessionPlaying(AudioSession defaultSession)
 {
     using (var sessionManager = GetDefaultAudioSessionManager2(DataFlow.Render))
     {
         using (var sessionEnumerator = sessionManager.GetSessionEnumerator())
         {
             foreach (var session in sessionEnumerator)
             {
                 if (session.GroupingParam == defaultSession.groupingParam)
                 {
                     using (var audioMeterInformation = session.QueryInterface<AudioMeterInformation>())
                     {
                         // Sometimes very very small but not 0 even when not playing
                         if(audioMeterInformation.PeakValue > 0.0001)
                         {
                             return true;
                         }
                     }
                 }
             }
         }
     }
     return false;
 }
Exemplo n.º 4
0
 // Pause or Unpause audiosession
 public void TogglePause(AudioSession defaultSession)
 {
     using (var sessionManager = GetDefaultAudioSessionManager2(DataFlow.Render))
     {
         using (var sessionEnumerator = sessionManager.GetSessionEnumerator())
         {
             foreach (var session in sessionEnumerator)
             {
                 using (var audioMeterInformation = session.QueryInterface<AudioMeterInformation>())
                 using (var session2 = session.QueryInterface<AudioSessionControl2>())
                 {
                     if (session.GroupingParam == defaultSession.groupingParam && session2.Process != null)
                     {
                         SendMessageW(session2.Process.MainWindowHandle, WM_APPCOMMAND, session2.Process.MainWindowHandle, (IntPtr)APPCOMMAND_MEDIA_PLAY_PAUSE);
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 5
0
 // Mute or unmute the audioSession
 public void Mute(AudioSession defaultSession, bool mute)
 {
     using (var sessionManager = GetDefaultAudioSessionManager2(DataFlow.Render))
     {
         using (var sessionEnumerator = sessionManager.GetSessionEnumerator())
         {
             foreach (var session in sessionEnumerator)
             {
                 if (session.GroupingParam == defaultSession.groupingParam)
                 {
                     using (var simpleVolume = session.QueryInterface<SimpleAudioVolume>())
                     {
                         simpleVolume.IsMuted = mute;
                     }
                 }
             }
         }
     }
 }