Esempio n. 1
0
 /// <summary>
 /// Constructor
 /// </summary>
 public QueueResponse(Queue queue)
 {
     if (queue == null) {
         this.Items = new List<object>();
     }
     else {
         this.Items = queue.CurrentAndUpcoming.Take(21).Select(i => QueueItemObject(i));
         this.PriorityCount = queue.UpcomingPriorityCount;
         this.Shuffle = queue.Shuffle;
         this.Repeat = Enum.GetName(typeof(RepeatMode), queue.Repeat).ToCamelCase(false);
     }
 }
Esempio n. 2
0
        Queue BuildBasicQueue()
        {
            var queue = new Queue();

            queue.Push(new DummyQueueItem(1, "First item"));
            queue.Push(new DummyQueueItem(2, "Second item"));
            queue.Push(new DummyQueueItem(3, "Third item"));
            queue.Push(new DummyQueueItem(4, "Fourth item"));
            queue.Push(new DummyQueueItem(5, "Fifth item"));
            queue.Push(new DummyQueueItem(6, "Sixth item"));
            queue.Push(new DummyQueueItem(7, "Seventh item"));
            queue.Push(new DummyQueueItem(8, "Eight item"));
            queue.Push(new DummyQueueItem(9, "Ninth item"));
            queue.Push(new DummyQueueItem(10, "Tenth item"));

            return queue;
        }
 /// <summary>
 /// Called when the contents of a queue has changed
 /// </summary>
 /// <param name="queue">The queue whos contents have changed</param>
 void queue_ItemsUpdated(Queue queue)
 {
 }
 /// <summary>
 /// Nicely stops a queue and the player it has
 /// </summary>
 /// <param name="queue">The queue to stop</param>
 void StopQueue(Queue queue)
 {
     StopPlayer(queue.CurrentPlayer);
     queue.CurrentPlayer = null;
     queue.IndexChanged -= queue_IndexChanged;
     queue.ItemsUpdated -= queue_ItemsUpdated;
     queue.Finished -= queue_Finished;
     queue.Dispose();
 }
 /// <summary>
 /// Called when a queue is done
 /// </summary>
 /// <param name="queue">The corresponding queue</param>
 void queue_Finished(Queue queue)
 {
     StopQueue(queue);
 }
        /// <summary>
        /// Called when the index of the current queue is changed. Starts playing the next track
        /// </summary>
        /// <param name="queue">The queue whos index has changed</param>
        /// <param name="previous">The previous item that was played</param>
        /// <param name="current">The item that is about the be played</param>
        void queue_IndexChanged(Queue queue, IItem previous, IItem current)
        {
            // If we have a different type to play, start the correct player and stop colliding players
            if (previous == null || previous.GetType() != current.GetType()) {

                // Get the player for the current item
                var newPlayer = GetPlayerForItem(current);

                // None found
                if (newPlayer == null) {
                    Log("No player found for item with type " + current.GetType().ToString(), Logger.LogLevel.Error);
                    StopQueue(queue);
                    return;
                }

                // Stop queues and players that collide with the new one
                var queues = Queue.Where(q => q != queue).ToList();
                foreach (var q in queues) {
                    if (q.CurrentPlayer is IAudioPlayer && newPlayer is IAudioPlayer)
                        StopQueue(q);
                    else if (q.CurrentPlayer is IVisualPlayer && newPlayer is IVisualPlayer)
                        StopQueue(q);
                }

                // If we are using an other player, stop the old one and set the necessary callbacks
                if (newPlayer != queue.CurrentPlayer) {
                    StopPlayer(queue.CurrentPlayer);
                    newPlayer.PlaybackFinished += player_PlaybackFinished;
                    queue.CurrentPlayer = newPlayer;
                }

            }

            // Play the current item
            queue.CurrentPlayer.Play(current);
        }
 /// <summary>
 /// Resume the playback of the current item in the queue
 /// </summary>
 /// <param name="queue">The queue to apply this action on</param>
 public void Play(Queue queue)
 {
     if (queue.CurrentPlayer != null)
         queue.CurrentPlayer.Play();
 }
 /// <summary>
 /// Skip to the next item in the current queue
 /// </summary>
 /// <param name="queue">The queue to apply this action on</param>
 public void Prev(Queue queue)
 {
     if (queue.IsAtFirstItem)
         queue.Index = 0;
     else
         queue.GoPrev();
 }
 /// <summary>
 /// Pause the playback of the current item in the queue
 /// </summary>
 /// <param name="queue">The queue to apply this action on</param>
 public void Pause(Queue queue)
 {
     if (queue.CurrentPlayer != null)
         queue.CurrentPlayer.Pause();
 }
        /// <summary>
        /// Start playing a set of items
        /// </summary>
        /// <param name="container">The container in which the items reside</param>
        /// <param name="filter">Filter used to get the items from the container</param>
        public Queue Play(Container container, Options filter)
        {
            // Get the plugin for the container
            var contentsPlugin = Plugins.GetContentsPluginFor(container);
            if (contentsPlugin == null) return null;

            // Get the items for this container / filter combination
            var items = contentsPlugin.GetItems(container, filter);

            // Bail out if no items
            if (items.Count() == 0) return null;

            // Build queue and queue info object
            var queue = new Queue(items, container.ContentType);

            // Find existing queue of same type
            var existingQueue = Queue.FirstOrDefault(q => q.ContentType == queue.ContentType);

            // If we have a similar queue, move repeat and shuffle settings
            if (existingQueue != null) {
                queue.Repeat = existingQueue.Repeat;
                queue.Shuffle = existingQueue.Shuffle;
            }

            // Set callbacks on queue
            queue.IndexChanged += queue_IndexChanged;
            queue.ItemsUpdated += queue_ItemsUpdated;
            queue.Finished += queue_Finished;

            // Save the queue
            queue.Save();

            // Set index, starting the queue
            var id = filter.GetInt("id");
            if (id > 0) {
                var item = items.FirstOrDefault(i => i.ID == id);
                queue.Current = item;
            }
            else
                queue.Index = filter.GetInt("index");

            return queue;
        }
 /// <summary>
 /// Skip to the previous item in the current queue
 /// </summary>
 /// <param name="queue">The queue to apply this action on</param>
 public void Next(Queue queue)
 {
     queue.GoNext();
 }
Esempio n. 12
0
 /// <summary>
 /// Called when the contents of the current Queue are changed
 /// </summary>
 void QueueItemsUpdated(Queue queue)
 {
     BroadcastQueue(queue);
 }
Esempio n. 13
0
        /// <summary>
        /// Called when the index of the current Queue is changed
        /// </summary>
        /// <param name="queue"></param>
        void QueueIndexChanged(Queue queue)
        {
            BroadcastQueue(queue);

            if (queue.Current != null)
                Play(queue.Current.Item);
            else {
                ClearPlayer();
                if (queue == this.Queue)
                    this.Queue = null;
            }
        }
Esempio n. 14
0
 void BroadcastQueue(Queue queue)
 {
     //ThrottledBroadcast(queue, () => {
         _server.Broadcast(new QueueResponse(queue));
     //});
 }
Esempio n. 15
0
 /// <summary>
 /// Applies the given queue as the current queue
 /// </summary>
 /// <param name="queue">The queue to apply</param>
 /// <returns>The applied queue</returns>
 Queue ApplyQueue(Queue queue)
 {
     queue.ItemsUpdated += QueueItemsUpdated;
     queue.IndexChanged += QueueIndexChanged;
     return this.Queue = queue;
 }