Пример #1
0
        public QueueItem EnqueueSong(string playerName, string playerHexColor, int songId, bool secret)
        {
            lock (_sync)
            {
                var song = _categories.SelectMany(c => c.Songs).FirstOrDefault(s => s.Id == songId);

                if (song == null) return null;

                var item = new QueueItem
                {
                    Player = new Player
                    {
                        Name = playerName,
                        HexColor = playerHexColor
                    },
                    Song = song,
                    Secret = secret,
                };

                _queue.Enqueue(item);

                return item;
            }
        }
Пример #2
0
        public void Start()
        {
            if (Interlocked.CompareExchange(ref _started, 1, 0) == 1)
            {
                throw new InvalidOperationException("Runner already started.");
            }

            ThreadPool.QueueUserWorkItem(async v =>
            {
                while (_running)
                {
                    var current = _songRepository.PopQueue();

                    if (current == null)
                    {
                        CurrentSong = null;
                        await Task.Delay(100);
                        continue;
                    }

                    CurrentSong = current;

                    var path = _settingsRepository.MplayerPath;

                    if (!File.Exists(path)) continue;

                    var pssi = new ProcessStartInfo(_settingsRepository.MplayerPath)
                    {
                        Arguments = $"-slave -quiet \"{current.Song.Path}\" -fs",
                        UseShellExecute = false,
                        CreateNoWindow = true,
                        RedirectStandardInput = true
                    };

                    _process = Process.Start(pssi);

                    if (_process == null) continue;

                    _process.WaitForExit();

                    Thread.Sleep(TimeSpan.FromSeconds(2));
                }

            });
        }