Ejemplo n.º 1
0
        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();
                    }
                }
            });
        }
Ejemplo n.º 2
0
        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);
            });
        }
Ejemplo n.º 3
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public static void Pause()
 {
     SoundEventLogger.LogBg("Pause");
     if (_runCommand(ActiveBgMusic.PauseCommand))
     {
         UpdateMusicState(BgMusicState.Pause);
     }
 }
Ejemplo n.º 5
0
        public static void Play()
        {
            SoundEventLogger.LogBg("Play");

            Unmute();
            //if (_runCommand(ActiveBgMusic.PlayCommand))
            //{
//                UpdateMusicState(BgMusicState.Play);
            //}
        }
Ejemplo n.º 6
0
 public static void Restore()
 {
     SoundEventLogger.LogBg("Restore");
     if (MusicState == BgMusicState.Mute)
     {
         Unmute();
     }
     else if ((MusicState == BgMusicState.Stop) || (MusicState == BgMusicState.Pause))
     {
         Play();
     }
 }
Ejemplo n.º 7
0
 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);
     }
 }
Ejemplo n.º 8
0
        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);
            }
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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);
            });
        }
Ejemplo n.º 11
0
 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);
     });
 }
Ejemplo n.º 12
0
        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);
        }