private void window_Closed(object sender, EventArgs e) { for (int index = 0; index < db.ignores.Count; index++) { CheckBox checkbox = (CheckBox)listIgnore.Items[index]; PauseIgnore ignore = db.ignores[index]; ignore.enable = checkbox.IsChecked == true; } }
private void btnOption_Clicked(object sender, RoutedEventArgs e) { if (listIgnore.SelectedIndex >= 0 && listIgnore.SelectedIndex < db.recentlyIgnores.Count) { PauseIgnore ignore = db.recentlyIgnores[listIgnore.SelectedIndex]; IgnoreOption page = new IgnoreOption(ignore); bool? result = page.ShowDialog(); if (result == true) { CheckBox checkbox = (CheckBox)listIgnore.SelectedItem; checkbox.Content = ignore.title; } } }
private void btnAdd_Clicked(object sender, RoutedEventArgs e) { if (listRecently.SelectedIndex >= 0) { PauseIgnore ignore = db.recentlyIgnores[listRecently.SelectedIndex]; IgnoreOption page = new IgnoreOption(ignore); bool? result = page.ShowDialog(); if (result == true) { db.recentlyIgnores.RemoveAt(listRecently.SelectedIndex); listRecently.Items.RemoveAt(listRecently.SelectedIndex); ignore.enable = true; db.ignores.Add(ignore); CheckBox checkbox = new CheckBox() { Content = ignore.title, IsChecked = ignore.enable }; listIgnore.Items.Add(checkbox); } } }
private void TimerAutoPause_Elapsed(object sender, ElapsedEventArgs e) { Dispatcher.Invoke((Action) delegate() { if (!playerDB.autoPause) { return; } using (MMDevice defaultDevice = devEnum.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia)) { bool foundOtherVolume = false; for (int index = 0; index < defaultDevice.AudioSessionManager.Sessions.Count; index++) { var session = defaultDevice.AudioSessionManager.Sessions[index]; if (!session.GetSessionIdentifier.Contains("FPlayer.exe")) { if (session.AudioMeterInformation.MasterPeakValue > 0.1) { var ignores = playerDB.ignores.Where(pauseIgnore => pauseIgnore.path == session.GetSessionIdentifier); bool foundIgnore = false; bool existIgnore = ignores.Count() > 0; foreach (PauseIgnore pauseIgnore in ignores) { if (pauseIgnore.enable) { foundIgnore = true; } } if (!foundIgnore) { foundOtherVolume = true; } if (!existIgnore) { bool foundRecently = playerDB.recentlyIgnores.Where(pauseIgnore => pauseIgnore.path == session.GetSessionIdentifier).Count() > 0; if (!foundRecently) { string sessionId; if (session.IconPath.Contains(@"System32\AudioSrv.Dll")) { sessionId = "系統音效"; } else { var sessionSplit = session.GetSessionIdentifier.Split(new string[] { @"\" }, StringSplitOptions.RemoveEmptyEntries); if (sessionSplit.Length > 0) { sessionId = sessionSplit.Last().Split(new string[] { @"%b" }, StringSplitOptions.RemoveEmptyEntries).First(); } else { sessionId = session.GetSessionIdentifier; } } PauseIgnore pauseIgnore = new PauseIgnore() { title = sessionId, path = session.GetSessionIdentifier, enable = false }; playerDB.recentlyIgnores.Add(pauseIgnore); } } } } if (foundOtherVolume) { autoPauseTime = DateTime.Now; if (audioPlayer.PlaybackState == PlaybackState.Playing) { playerState = PlayerState.AutoPause; audioPlayer.Pause(); } } else { TimeSpan distance = DateTime.Now - autoPauseTime; if (distance.TotalSeconds > autoPauseGap && audioPlayer.PlaybackState == PlaybackState.Paused && audioPlayerItem != null && playerState == PlayerState.AutoPause) { playerState = PlayerState.Playing; audioPlayer.Play(); } } } } }); }
public IgnoreOption(PauseIgnore ignore) { InitializeComponent(); this.ignore = ignore; }