public void NextItem()

in Samples-NetCore/MusicManager/MusicManager.Domain/Playlists/PlaylistManager.cs [114:148]


        public void NextItem()
        {
            if (!CanNextItem) throw new InvalidOperationException("Call this method only if CanNextItem is true.");
            int currentItemIndex = items.IndexOf(CurrentItem);
            int index;
            if (!Shuffle)
            {
                index = currentItemIndex + 1;
            }
            else
            {
                if (items.Count <= playedItemsStack.Count + 1)
                {
                    playedItemsStack.Clear();
                }
                index = randomService.NextRandomNumber(items.Count - playedItemsStack.Count - 2);
                for (int i = 0; i < items.Count; i++)
                {
                    if (CurrentItem == Items[i])
                    {
                        index++;
                    }
                    else if (playedItemsStack.Contains(Items[i]))
                    {
                        index++;
                    }
                    if (index <= i)
                    {
                        break;
                    }
                }
            }
            index = index < items.Count ? index : 0;
            CurrentItem = Items[index];
        }