protected override void OnResetItems(IEnumerable <PlaylistItem> sourceItems, PlaylistItem item) { var copied = sourceItems.ToList(); // 再生済みアイテムを同期 var existPlayedItems = PlayedItem.Where(x => copied.Any(y => y.ContentId == x.ContentId)); PlayedItem = new Stack <PlaylistItem>(existPlayedItems); // ランダム化したアイテムの同期 RandamizedItems.Clear(); var shuffledUnplayItems = copied .Where(x => !PlayedItem.Any(y => x.ContentId == y.ContentId)) .Shuffle(); foreach (var shuffled in shuffledUnplayItems) { RandamizedItems.Enqueue(shuffled); } // Currentを同期 // 現在再生中のアイテムが削除されていた場合、Currentをnullにするだけ if (Current != null && !copied.Any(x => x.ContentId == Current.ContentId)) { Current = null; } }
private void ResetRandmizedItems(IEnumerable <PlaylistItem> items) { RandamizedItems.Clear(); if (items != null) { var firstItem = items.Take(1).SingleOrDefault(); if (firstItem != null) { RandamizedItems.Add(firstItem); RandamizedItems.AddRange(items.Skip(1).Shuffle()); } } }
private void ResetRandmizedItems() { RandamizedItems.Clear(); if (SourceItems != null) { var firstItem = SourceItems.Take(1).SingleOrDefault(); if (firstItem != null) { RandamizedItems.Add(firstItem); RandamizedItems.AddRange(SourceItems.Skip(1).Shuffle()); } } }