private void ResumeBGMusic()
 {
     if (CurrentTable != null)
     {
         if (CurrentTable.BGMusicExists)
         {
             BGMusicPlayer.Play();
         }
     }
 }
 //Change Background Music to the current table
 private void ChangeBGMusic()
 {
     BGMusicPlayer.Stop();
     if (CurrentTable != null)
     {
         if (CurrentTable.BGMusicExists)
         {
             BGMusicPlayer.Open(CurrentTable.BGMusic);
             BGMusicPlayer.Play();
         }
     }
 }
Exemplo n.º 3
0
    void Awake()
    {
        //Singleton stuff
        if (musicInstance != null && musicInstance != this)
        {
            Destroy(this.gameObject);
            return;
        }

        musicInstance = this;
        myAudioSource = GetComponent <AudioSource>();
    }
 private void StopBGMusic()
 {
     BGMusicPlayer.Stop();
 }
        private async Task StartTableAsync(int mainThread)
        {
            logger.Info($"{RunMode.ToString()}: Starting table: {CurrentTable.Name}");
            RunMode = Mode.SystemRunning;
            logger.Trace($"Setting Mode to {RunMode.ToString()}");

            //Play Launch Music
            LMusicPlayer.Open(CurrentTable.LMusic);
            LMusicPlayer.Play();

            var system = Data.FindSystem(CurrentTable);                     // get system to launch
            var proc   = PinballFunctions.StartTable(system, CurrentTable); // launch system



            Stopwatch watchdog = new Stopwatch();

            watchdog.Reset();
            watchdog.Start();


            //Wait for process to start (done this way for steam games)
            logger.Info($"Starting Game Process, Name: {system.Name}");
            //proc.WaitForInputIdle();
            await Task.Run(() => { while (Process.GetProcessesByName(system.Name).Length <= 0)
                                   {
                                       ;
                                   }
                           });

            var game = Process.GetProcessesByName(system.Name).First();

            logger.Info($"Game Process Found, Handle: {game.Id}");

            //keep hiding while window is starting
            await Task.Run(() =>
            {
                do
                {
                    //WindowControl.HideAllProcessWindows(system.Name, true);
                } while (WindowControl.FindProcessWindow(system.Name, system.WindowName) == IntPtr.Zero);
                //WindowControl.HideAllProcessWindows(system.Name);
            });

            var windowHandle = WindowControl.FindProcessWindow(system.Name, system.WindowName);

            WindowControl.HideWindow(windowHandle, true);
            logger.Info($"Game Window Found, Process: {system.Name}, Name: {system.WindowName}, Handle: {windowHandle}");



            //Try and Mute System
            watchdog.Restart();
            logger.Info("Muting System");
            await Task.Run(() =>
            {
                while (VolumeMixer.GetApplicationMute(game.Id) != true)
                {
                    //Console.WriteLine("Trying to Mute");
                    VolumeMixer.SetApplicationMute(game.Id, true);
                    //WindowControl.SetFocus(ProgramName);
                    if (watchdog.ElapsedMilliseconds > 10000)
                    {
                        logger.Warn($"Can't Mute System, Process ID: {game.Id}");
                        break;
                    }
                }
            });



            //Wait for Game to load
            await Task.Run(() => Task.Delay(system.WaitTime * 1000));

            BGMusicPlayer.Pause();

            //Unmute
            watchdog.Restart();
            logger.Info("Unmuting System");
            while (VolumeMixer.GetApplicationMute(game.Id) != false)
            {
                //Console.WriteLine("Trying to Unmute");
                VolumeMixer.SetApplicationMute(game.Id, false);
                //WindowControl.SetFocus(ProgramName);
                if (watchdog.ElapsedMilliseconds > 10000)
                {
                    logger.Warn($"Can't Unmute System, Process ID: {game.Id}");
                    break;
                }
            }


            //Show Game Window
            WindowControl.ShowWindow(windowHandle, true);

            //Focus GAME
            WindowControl.SetFocusForeground(windowHandle, true);

            //Hide Selected Windows
            logger.Trace("Setting Window Visibility");
            BackglassWindow.Visibility = CurrentTable.ShowBackglass ? Visibility.Visible : Visibility.Hidden;
            DMDWindow.Visibility       = CurrentTable.ShowDMD ? Visibility.Visible : Visibility.Hidden;
            PlayfieldVisibility        = Visibility.Hidden;
        }