コード例 #1
0
 internal void AddToFront(QueuedPlayableContext queuedPlayableContext)
 {
     lock (m_queuedPlayables)
     {
         m_queuedPlayables.Insert(0, queuedPlayableContext);
     }
 }
コード例 #2
0
 internal void Add(QueuedPlayableContext queuedPlayableContext)
 {
     lock (m_queuedPlayables)
     {
         m_queuedPlayables.Add(queuedPlayableContext);
     }
 }
コード例 #3
0
        internal void FinishedPlaying(QueuedPlayableContext ctxt)
        {
            lock (m_queuedPlayables)
            {
                if (ctxt == CurrentlyPlaying)
                {
                    LastPlayFinish = DateTime.Now;

                    CurrentlyPlaying = null;
                }
            }
        }
コード例 #4
0
        void PlayNextSequentialContent(PlayableContentQueue queue)
        {
            QueuedPlayableContext ctxt = null;

            lock (queue.SyncRoot)
            {
                if (queue.CurrentlyPlaying != null)
                {
                    return;
                }

                ctxt = queue.GetNext();
            }

            Action next = () =>
            {
                if (ctxt.OnClose != null)
                {
                    ctxt.OnClose();
                }

                lock (queue.SyncRoot)
                {
                    queue.FinishedPlaying(ctxt);
                }

                PlayNextSequentialContent(queue);
            };

            if (ctxt != null)
            {
                var playable = ctxt.Playable;

                if (ctxt.OnPlay != null)
                {
                    ctxt.OnPlay(ctxt.ActivationContext, playable, next);
                }
                else if (ctxt.OnClose != null)
                {
                    next();
                }
            }
        }
コード例 #5
0
        protected virtual void AddToQueue(PlayableContentQueue queue, ResourceActivationContext activationContext, PlayableContent playable, PlayContentDelegate onPlay, Action onClose)
        {
            lock (m_queues)
            {
                m_queues.Add(activationContext.InstanceId, queue);
            }

            switch (playable.Priority)
            {
            case PlayableContentPriority.High:
                // Todo: actually want to be a bit more clever and *don't* move in front of
                // other high priority ones.
                queue.AddToFront(
                    new QueuedPlayableContext
                {
                    ActivationContext = activationContext,
                    Playable          = playable,
                    OnClose           = onClose,
                    OnPlay            = onPlay
                });

                PlayNextSequentialContent(queue);
                break;

            case PlayableContentPriority.Interrupt:
                QueuedPlayableContext toStop = null;

                lock (queue.SyncRoot)
                {
                    toStop = queue.CurrentlyPlaying;
                }

                if (toStop != null)
                {
                    StopPlaying(toStop.ActivationContext, toStop.Playable, true);
                    toStop.ActivationContext.Close();
                }

                queue.AddToFront(
                    new QueuedPlayableContext
                {
                    ActivationContext = activationContext,
                    Playable          = playable,
                    OnClose           = onClose,
                    OnPlay            = onPlay
                });

                PlayNextSequentialContent(queue);
                break;

            case PlayableContentPriority.Filler:
                // Only if nothing has played on this queue for a while...
                bool doPlay = false;

                lock (queue.SyncRoot)
                {
                    doPlay = queue.CurrentlyPlaying == null &&
                             (DateTime.Now - queue.LastPlayFinish).TotalSeconds >= MinFillerDelay;
                }

                if (doPlay)
                {
                    queue.Add(
                        new QueuedPlayableContext
                    {
                        ActivationContext = activationContext,
                        Playable          = playable,
                        OnClose           = onClose,
                        OnPlay            = onPlay
                    });

                    PlayNextSequentialContent(queue);
                }
                break;

            case PlayableContentPriority.Normal:
            default:
                queue.Add(
                    new QueuedPlayableContext
                {
                    ActivationContext = activationContext,
                    Playable          = playable,
                    OnClose           = onClose,
                    OnPlay            = onPlay
                });

                PlayNextSequentialContent(queue);
                break;
            }
        }