示例#1
0
        private int AddSong(int songId)
        {
            // Keep queue trimmed
            if (LookupMap.Count >= MAX_QUEUE_SIZE)
            {
                PlayQueueEntryModel head = null;

                if (PlaybackQueue.Count > 0)
                {
                    head = PlaybackQueue.First();
                }

                if (head != null)
                {
                    if (CurrentPlaybackQueueEntryId == head.RowId)
                    {
                        // TODO: #6 raise alert about queue being full
                        return -1;
                    }
                    else
                    {
                        RemoveEntry(head.RowId);
                    }
                }
            }

            PlayQueueEntryModel currentTail = null;

            if (PlaybackQueue.Count > 0)
            {
                currentTail = PlaybackQueue.Last();
            }

            PlayQueueEntryTable newPlayQueueEntry;

            if (currentTail == null)
            {
                newPlayQueueEntry = new PlayQueueEntryTable(songId, 0, 0);

                DatabaseManager.Current.AddPlayQueueEntry(newPlayQueueEntry);
            }
            else
            {
                newPlayQueueEntry = new PlayQueueEntryTable(songId, 0, currentTail.RowId);
               
                DatabaseManager.Current.AddPlayQueueEntry(newPlayQueueEntry);

                currentTail.NextId = newPlayQueueEntry.RowId;
            }

            PlayQueueEntryModel newEntry = new PlayQueueEntryModel(newPlayQueueEntry);

            LookupMap.Add(newEntry.RowId, newEntry);
            PlaybackQueue.Add(newEntry);

            NotifyPropertyChanged(Properties.NextTrack);
            NotifyPropertyChanged(Properties.PrevTrack);

            return newEntry.RowId;
        }
示例#2
0
        public void Populate()
        {
            Logger.Current.Log(new CallerInfo(), LogLevel.Info, "Calling Popuplate");

            List<PlayQueueEntryTable> allEntries = DatabaseManager.Current.FetchPlayQueueEntries();

            PlayQueueEntryModel head = null;

            foreach (PlayQueueEntryTable playQueueEntry in allEntries)
            {
                PlayQueueEntryModel newEntry = new PlayQueueEntryModel(playQueueEntry);

                LookupMap.Add(newEntry.RowId, newEntry);

                if (newEntry.PrevId == 0)
                {
                    DebugHelper.Assert(new CallerInfo(), head == null, "Second head found in play queue!!!");

                    head = newEntry;
                }
            }

            PlayQueueEntryModel currentLocation = head;

            while (currentLocation != null && PlaybackQueue.Count < LookupMap.Count)
            {
                PlaybackQueue.Add(currentLocation);

                if (LookupMap.ContainsKey(currentLocation.NextId))
                {
                    currentLocation = LookupMap[currentLocation.NextId];
                }
                else
                {
                    currentLocation = null;
                }
            }

            DebugHelper.Assert(new CallerInfo(), currentLocation == null, "Circular reference found in Play Queue");
            DebugHelper.Assert(new CallerInfo(), PlaybackQueue.Count == LookupMap.Count, "Missing element found in Play Queue");

            CurrentPlaybackQueueEntryId = ApplicationSettings.GetSettingsValue<int>(ApplicationSettings.CURRENT_PLAYQUEUE_POSITION, 0);

            if (CurrentPlaybackQueueEntryId == 0)
            {
                ResetPlayerToStart();
            }
        }