コード例 #1
0
        private void Run()
        {
            players = LoadSounds();

            Window hiddenWindow = new Window()
            {
                Width         = 0,
                Height        = 0,
                WindowStyle   = WindowStyle.None,
                ShowInTaskbar = false,
                ShowActivated = false
            };

            hiddenWindow.Visibility = Visibility.Hidden;
            hiddenWindow.Loaded    += (s, o) =>
            {
                _current = this;
                Thread.CurrentThread.IsBackground = true;
                DispatcherTimer t = new DispatcherTimer();
                t.Interval = TimeSpan.FromMilliseconds(1);
                t.Tick    += (s1, o1) =>
                {
                    Queue <SoundAction> toRun = new Queue <SoundAction>();
                    lock (soundQueue)
                    {
                        while (soundQueue.Count > 0)
                        {
                            toRun.Enqueue(soundQueue.Dequeue());
                        }
                    }

                    while (toRun.Count > 0)
                    {
                        var next = toRun.Dequeue();
                        if (next is StopSoundThreadAction)
                        {
                            t.Stop();
                            CurrentlyPlayingSounds.ToArray().ToList().ForEach(sound => sound.Dispose());
                            hiddenWindow.Close();
                            _current = null;
                        }
                        else
                        {
                            next.ToRun.Invoke();
                        }
                    }
                };
                t.Start();
            };
            hiddenWindow.Show();
            hiddenWindow.Visibility = Visibility.Hidden;
            Dispatcher.Run();
        }
コード例 #2
0
 public void Play(string name, bool loop)
 {
     if (HasSound(name) == false)
     {
         return;
     }
     EnqueueSoundThreadAction(() =>
     {
         var player    = players[name];
         players[name] = PreLoad(name);
         CurrentlyPlayingSounds.Add(new SoundPlaybackLifetime(player, loop, this));
     });
 }