CrewChiefV3.AudioPlayer.playSounds C# (CSharp) Метод

playSounds() приватный Метод

private playSounds ( List eventNames, System.Boolean isImmediateMessages, System.Boolean &wasInterrupted ) : List
eventNames List
isImmediateMessages System.Boolean
wasInterrupted System.Boolean
Результат List
        private List<String> playSounds(List<String> eventNames, Boolean isImmediateMessages, out Boolean wasInterrupted)
        {
            //Console.WriteLine("Playing sounds, events: " + String.Join(", ", eventNames));
            List<String> soundsProcessed = new List<String>();
            OrderedDictionary thisQueue = isImmediateMessages ? immediateClips : queuedClips;
            wasInterrupted = false;
            int playedEventCount = 0;
            foreach (String eventName in eventNames)
            {
                // if there's anything in the immediateClips queue, stop processing
                if (isImmediateMessages || immediateClips.Count == 0)
                {
                    if (thisQueue.Contains(eventName))
                    {
                        QueuedMessage thisMessage = (QueuedMessage)thisQueue[eventName];
                        if (!isImmediateMessages && playedEventCount > 0 && pauseBetweenMessages > 0)
                        {
                            Console.WriteLine("Pausing before " + eventName);
                            Thread.Sleep(TimeSpan.FromSeconds(pauseBetweenMessages));
                        }
                        if (clipIsPearlOfWisdom(eventName))
                        {
                            soundsProcessed.Add(eventName);
                            if (hasPearlJustBeenPlayed())
                            {
                                Console.WriteLine("Rejecting pearl of wisdom " + eventName +
                                    " because one has been played in the last " + minTimeBetweenPearlsOfWisdom + " seconds");
                                continue;
                            }
                            else if (!allowPearlsOnNextPlay)
                            {
                                Console.WriteLine("Rejecting pearl of wisdom " + eventName +
                                    " because they've been temporarily disabled");
                                continue;
                            }
                            else if (disablePearlsOfWisdom)
                            {
                                Console.WriteLine("Rejecting pearl of wisdom " + eventName +
                                       " because pearls have been disabled for the last phase of the race");
                                continue;
                            }
                            else
                            {
                                timeLastPearlOfWisdomPlayed = DateTime.UtcNow;
                                List<SoundPlayer> clipsList = clips[eventName];
                                int index = random.Next(0, clipsList.Count);
                                SoundPlayer clip = clipsList[index];
                                if (!mute)
                                {
                                    clip.PlaySync();
                                }
                            }
                        }
                        else
                        {
                            lastMessagePlayed = thisMessage;
                            foreach (String message in thisMessage.messageFolders)
                            {
                                List<SoundPlayer> clipsList = clips[message];
                                int index = random.Next(0, clipsList.Count);
                                SoundPlayer clip = clipsList[index];
                                if (!mute)
                                {
                                    clip.PlaySync();
                                }
                            }
                            if (playedMessagesCount.ContainsKey(eventName))
                            {
                                int count = playedMessagesCount[eventName] + 1;
                                playedMessagesCount[eventName] = count;
                            }
                            else
                            {
                                playedMessagesCount.Add(eventName, 1);
                            }
                            soundsProcessed.Add(eventName);
                        }
                        playedEventCount++;
                    }
                }
                else
                {
                    Console.WriteLine("we've been interrupted after playing " + playedEventCount + " events");
                    wasInterrupted = true;
                    break;
                }
            }
            if (soundsProcessed.Count == 0)
            {
                Console.WriteLine("Processed no messages in this queue");
                holdChannelOpen = true;
            }
            else
            {
                Console.WriteLine("*** Processed " + String.Join(", ", soundsProcessed.ToArray()));
            }
            return soundsProcessed;
        }