public void Add(MyAudioSession audioSession, Point screenCorner) { this.Topmost = true; // Adjust current corner this.Left = screenCorner.X - this.ActualWidth - 10; this.Top = screenCorner.Y - this.ActualHeight - 10; Timer timer; bool hasTimer = closeTimers.TryGetValue(audioSession.GetHashCode(), out timer); if (hasTimer == false) { AudioSessions.Add(audioSession); timer = new Timer(2000); timer.AutoReset = false; timer.Elapsed += (s, e) => Timer_Elapsed(s, e, audioSession); closeTimers[audioSession.GetHashCode()] = timer; } // Reset Timer timer.Stop(); timer.Start(); }
private static void addSessionsForEndpoint(List <MyAudioSession> sessionList, MMDevice endpoint) { var sessions = endpoint.AudioSessionManager.Sessions; for (int i = 0; i < sessions.Count; i++) { var audioSession = new MyAudioSession(); audioSession.AudioSessionControl = sessions[i]; var processID = (int)audioSession.AudioSessionControl.GetProcessID; var process = Process.GetProcessById(processID); var FriendlyName = process.ProcessName; audioSession.FriendlyName = FriendlyName; if (sessionList.Exists(a => a.AudioSessionControl.GetProcessID == processID)) { audioSession.FriendlyName += " (@" + endpoint.DeviceFriendlyName + ")"; } if (processID > 0) // && !sessionList.Exists(a => a.AudioSessionControl.GetProcessID == processID)) { // Extract and store icon try { Icon ico = Icon.ExtractAssociatedIcon(process.MainModule.FileName); BitmapSource iconImage = Imaging.CreateBitmapSourceFromHIcon(ico.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); audioSession.IconImage = iconImage; } catch { } // Init Volume audioSession.ChangeVolumeExternal(audioSession.AudioSessionControl.SimpleAudioVolume.Volume); audioSession.AudioSessionControl.RegisterEventClient(new MyEventHandler(audioSession)); sessionList.Add(audioSession); } } }
private void Remove(MyAudioSession audioSession) { Console.WriteLine("removing " + audioSession.FriendlyName); AudioSessions.Remove(audioSession); }
private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e, MyAudioSession audioSession) { ((Timer)sender).Stop(); closeTimers.Remove(audioSession.GetHashCode()); this.Dispatcher.Invoke(() => Remove(audioSession)); }
public MyEventHandler(MyAudioSession audioSession) { this.audioSession = audioSession; }