public static void Close() { WinSoundServer.WinSoundServerSysTray.Instance.Invoke((System.Windows.Forms.MethodInvoker) delegate { SoundEventLogger.LogBg("Close"); if ((ActiveBgMusic.IsWeb == false)) //&& (OwnBgMusicPid == true) { for (int i = 0; i < BgMusicPids.Length; i++) { try { System.Diagnostics.Process proc = System.Diagnostics.Process.GetProcessById(BgMusicPids[i]); proc.Kill(); } catch (Exception ex) { System.Diagnostics.Debug.Write(ex); string msg = ex.Message; } } BgMusicPids = new int[] { }; OwnBgMusicPid = false; } else { // Don't leave background music hidden if (BgMusicWindowShown == false) { Show(); } } }); }
public static void Show() { WinSoundServer.WinSoundServerSysTray.Instance.Invoke((System.Windows.Forms.MethodInvoker) delegate { SoundEventLogger.LogBg("Show"); if (BgMusicPids.Length == 0) { _run(); if (BgMusicPids.Length == 0) { return; } } if (ActiveBgMusic.IsWeb) { WinSoundServerSysTray.WebBgMusicForm.UnstopSounds(); WinSoundServerSysTray.WebBgMusicForm.Show(); if (WinSoundServerSysTray.WebBgMusicForm.WindowState == System.Windows.Forms.FormWindowState.Minimized) { WinSoundServerSysTray.WebBgMusicForm.WindowState = System.Windows.Forms.FormWindowState.Normal; } SetForegroundWindow(WinSoundServerSysTray.WebBgMusicForm.Handle); } else { for (int i = 0; i < BgMusicPids.Length; i++) { WinSoundServer.Operation.Show(BgMusicPids[i], -1); } } UpdateWindowShownState(true); }); }
private static void _run() { if (ActiveBgMusic.IsWeb) { WinSoundServerSysTray.WebBgMusicForm.LoadSite(ActiveBgMusic.Name, ActiveBgMusic.UrlOrCommandLine); System.Diagnostics.Process p = System.Diagnostics.Process.GetCurrentProcess(); BgMusicPids = (p != null) ? new int[] { p.Id } : new int[] { }; SoundEventLogger.LogBg("RunWeb"); } else { //Figure out procname. Process[] processes = (Process.GetProcessesByName("iTunes")); //TO_DO: might not match // was ActiveBgMusic.UrlOrCommandLine if (processes.Length > 1) { System.Diagnostics.Debug.WriteLine("Process '" + ActiveBgMusic.UrlOrCommandLine + " does not seem to be unique!"); return; } else if (processes.Length == 1) { BgMusicPids = new int[] { processes[0].Id }; OwnBgMusicPid = false; BgMusicProcess = processes[0]; BgMusicProcess.EnableRaisingEvents = true; BgMusicProcess.Exited += new EventHandler(OnBgMusicExited); } else // Launch a new process { try { Operation.PROCESS_INFORMATION processInfo = Operation.CreateProc((ActiveBgMusic.UrlOrCommandLine + " " + ActiveBgMusic.CommandLineArgs).Trim()); uint pid = processInfo.dwProcessId; if (pid > 0) { //TODO-pid;//: also get children processes and include them BgMusicPids = new int[] { (int)pid }; BgMusicProcess = Process.GetProcessById((int)pid); BgMusicProcess.EnableRaisingEvents = true; BgMusicProcess.Exited += new EventHandler(OnBgMusicExited); OwnBgMusicPid = true; SoundEventLogger.LogBg("RunProc"); System.Threading.Thread.Sleep(2000); // Wait a bit before a command gets run so we don't have a race condition; don't like this but leaving it for now (since it ties up the ui thread for a bit) } else { BgMusicPids = new int[] { } }; } catch (Exception ex) { System.Diagnostics.Debug.Write(ex); } } } }
public static void Pause() { SoundEventLogger.LogBg("Pause"); if (_runCommand(ActiveBgMusic.PauseCommand)) { UpdateMusicState(BgMusicState.Pause); } }
public static void Play() { SoundEventLogger.LogBg("Play"); Unmute(); //if (_runCommand(ActiveBgMusic.PlayCommand)) //{ // UpdateMusicState(BgMusicState.Play); //} }
public static void Restore() { SoundEventLogger.LogBg("Restore"); if (MusicState == BgMusicState.Mute) { Unmute(); } else if ((MusicState == BgMusicState.Stop) || (MusicState == BgMusicState.Pause)) { Play(); } }
public static void SmartMute() { SoundEventLogger.LogBg("SmartMute"); // Pause if possible, otherwise mute. Should perhaps allow stop in addition to mute to save cpu and maybe network activity if ((ActiveBgMusic.PauseCommand != null) && (ActiveBgMusic.PauseCommand != "") && (MuteTunesConfig.GeneralSettings.FadeDownToLevel == 0)) { Mute(new PostVolumeOp(Pause), MuteTunesConfig.GeneralSettings.FadeDownToLevel); } else { Mute(null, MuteTunesConfig.GeneralSettings.FadeDownToLevel); } }
public static void Unmute() { SoundEventLogger.LogBg("Unmute"); if (AutoKillAfterMutedWorker != null) { AutoKillAfterMutedWorker.CancelAsync(); AutoKillAfterMutedWorker = null; } _runCommand(ActiveBgMusic.PlayCommand); //UpdateMusicState(BgMusicState.Play); for (int i = 0; i < BgMusicPids.Length; i++) { WinSoundServer.SmartVolManagerPackage.SoundServer.PerformOperation(BgMusicPids[i], OperationEnum.SetVolumeTo.ToString(), "1", null); } }
public static void Mute(Delegate afterMute, float fadeDownTo) { SoundEventLogger.LogBg("Mute"); for (int i = 0; i < BgMusicPids.Length; i++) { WinSoundServer.SmartVolManagerPackage.SoundServer.PerformOperation(BgMusicPids[i], OperationEnum.SetVolumeTo.ToString(), fadeDownTo.ToString(), afterMute); } if ((ActiveBgMusic.AutoKillWhenMuted == true) && (fadeDownTo == 0)) { AutoKillAfterMutedWorker = new System.ComponentModel.BackgroundWorker(); AutoKillAfterMutedWorker.WorkerSupportsCancellation = true; AutoKillAfterMutedWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(AutoKillAfterMutedWorker_DoWork); AutoKillAfterMutedWorker.RunWorkerAsync(); } UpdateMusicState(BgMusicState.Mute); }
public static void Stop() { WinSoundServer.WinSoundServerSysTray.Instance.Invoke((System.Windows.Forms.MethodInvoker) delegate { SoundEventLogger.LogBg("Stop"); if (ActiveBgMusic.IsWeb == false) { Close(); } else { WinSoundServerSysTray.WebBgMusicForm.StopSounds(); Hide(); } UpdateMusicState(BgMusicState.Stop); }); }
public static void Hide() { WinSoundServer.WinSoundServerSysTray.Instance.Invoke((System.Windows.Forms.MethodInvoker) delegate { SoundEventLogger.LogBg("Hide"); if (ActiveBgMusic.IsWeb) { WinSoundServerSysTray.WebBgMusicForm.Hide(); } else { for (int i = 0; i < BgMusicPids.Length; i++) { WinSoundServer.Operation.Hide(BgMusicPids[i], -1); } } UpdateWindowShownState(false); }); }
private static bool _runProcCommand(string command) { if (BgMusicPids.Length == 0) { _run(); if (BgMusicPids.Length == 0) { return(false); } } if ((command == null) || (command == "")) { return(false); } SoundEventLogger.LogBg("RunProc"); System.Diagnostics.Process p = System.Diagnostics.Process.Start(command); //TO_DO: maybe replace tokens, logging, hide console return(true); }