public async Task AddRandomSongAsync() { var song = await SelectRandomSongAsync().ConfigureAwait(false); // if for some reason could not find new song to play // then just add currently playing track to upcoming songs // (the same logic is implemented in synchronous version as well) UpcomingSongs.Add(song ?? CurrentSong); }
/// <summary> /// Method removes song by its ID from the list of upcoming songs /// and adds new randonly selected song to the list (to keep its size constant) /// </summary> public void RemoveSong(int songId) { for (var i = 0; i < MaxSongs; i++) { if (UpcomingSongs[i].Id != songId) { continue; } UpcomingSongs.RemoveAt(i); UpcomingSongs.Add(SelectRandomSong()); return; } }
public void AddRandomSong() => UpcomingSongs.Add(SelectRandomSong() ?? CurrentSong);