private void Playlist_CurrentSongChanged(object sender, CurrentSongChangedEventArgs args) { Song currentSong = args.NewCurrentSong; int shuffleIndex = GetCurrentSongIndex(Parent.Count); int currentSongIndex = IndexOf(currentSong); if (currentSongIndex == -1) { Song[] removes = this.Skip(Count - shuffleIndex - 1).ToArray(); List <Song> adds = GetRandomSongs(Parent, removes, Count - shuffleIndex); if (!adds.Remove(currentSong)) { adds.RemoveAt(0); } adds.Insert(0, currentSong); Change(removes, adds); } else if (currentSongIndex > shuffleIndex) { Song[] removes = this.Take(currentSongIndex - shuffleIndex).ToArray(); List <Song> adds = GetRandomSongs(Parent, removes, currentSongIndex - shuffleIndex); Change(removes, adds); } else if (currentSongIndex < shuffleIndex) { Song[] removes = this.Skip(Count - shuffleIndex + currentSongIndex).ToArray(); List <ChangeCollectionItem <Song> > adds = GetRandomSongs(Parent, removes, shuffleIndex - currentSongIndex). Select((c, i) => new ChangeCollectionItem <Song>(i, c)).ToList(); Change(removes, adds); } }
private void OnCurrentSongChanged(object sender, CurrentSongChangedEventArgs e) { CurrentSong.Unsubscribe(e.OldCurrentSong); CurrentSong.Subscribe(e.NewCurrentSong); OtherSongs.Unsubscribe(e.NewCurrentSong); OtherSongs.Subscribe(e.OldCurrentSong); CurrentSongChanged?.Invoke(this, new SubscriptionsEventArgs <IPlaylist, CurrentSongChangedEventArgs>(sender, e)); }
async void audioControls_CurrentSongChanged(object sender, CurrentSongChangedEventArgs e) { var library = this.library ?? await libraryLoadingTask; var currentSongFileName = ApplicationSettings.CurrentSongFileName.Read(); if (currentSongFileName == null) { this.NowPlaying = null; } else { var song = library.Songs.FirstOrDefault(p => p.FileName == currentSongFileName); this.NowPlaying = song; this.Playlist.UpdateSongChanged(e.Type, this.NowPlaying); if (SongChanged != null) SongChanged(this, e.Type); if (this.NowPlayingAlbum == null || !this.NowPlayingAlbum.Contains(song)) this.NowPlayingAlbum = library.Albums.FirstOrDefault(p => p.Contains(song)); } }