/// <summary> /// Attempts to play the next song in queue. /// </summary> private void PlayNextSong() { Application.Current.Dispatcher.Invoke(() => { if (reader != null && !isPlayerWaveOutAvailable && (Session.SongsIdPlayQueue.Count > 0 || Session.SongsIdSongList.Count > 0)) { int id; if (Session.SongsIdPlayQueue.Count > 0) { id = Session.SongsIdPlayQueue.First(); } else { id = Session.SongsIdSongList.First(); } Action update = () => { Session.HistoryIndex = Session.SongsIdPlayHistory.Count - 1; if (Session.SongsIdPlayQueue.Count > 0) { Session.SongsIdPlayQueue.RemoveAt(0); } else { Session.SongsIdSongList.RemoveAt(0); } RefreshPage(true); }; if (id > 0) { Song.FetchById(id, (song) => { Session.PlayerPage.PlaySong(song); update(); }, (errorResponse) => { MessageBox.Show(errorResponse.Message); }, () => { MessageBox.Show("Ocurrió un error al cargar la canción."); }); } else { AccountSong.FetchById(id * -1, (accountSong) => { Session.PlayerPage.PlayAccountSong(accountSong); update(); }, (errorResponse) => { MessageBox.Show(errorResponse.Message); }, () => { MessageBox.Show("Ocurrió un error al cargar la canción."); }); } } }); }
/// <summary> /// Attempts to play the previous played song. /// </summary> public void PreviousSong() { if (Session.HistoryIndex >= 0) { try { if (Session.SongsIdPlayHistory.ElementAt(Session.HistoryIndex) > 0) { Song.FetchById(Session.SongsIdPlayHistory.ElementAt(Session.HistoryIndex), (song) => { Session.HistoryIndex--; if (Session.SongsIdPlayHistory.Count == Core.MAX_SONGS_IN_HISTORY) { Session.HistoryIndex--; } ShouldPlayNextSong = false; Session.PlayerPage.PlaySong(song); RefreshPage(false); }, (errorResponse) => { MessageBox.Show(errorResponse.Message); }, () => { MessageBox.Show("Ocurrió un error al cargar la canción."); }); } else { AccountSong.FetchById(Session.SongsIdPlayHistory.ElementAt(Session.HistoryIndex) * -1, (accountSong) => { Session.HistoryIndex--; if (Session.SongsIdPlayHistory.Count == Core.MAX_SONGS_IN_HISTORY) { Session.HistoryIndex--; } ShouldPlayNextSong = false; Session.PlayerPage.PlayAccountSong(accountSong); RefreshPage(true); }, (errorResponse) => { MessageBox.Show(errorResponse.Message); }, () => { MessageBox.Show("Ocurrió un error al cargar la canción."); }); } } catch (Exception) { MessageBox.Show("Ocurrió un error al cargar la canción."); } } }
public void FetchNotOwnedByIdTest() { AutoResetEvent autoResetEvent = new AutoResetEvent(false); bool pass = false; Account.Login("*****@*****.**", "1230", (account) => { AccountSong.FetchById(1000, (accountSong) => { autoResetEvent.Set(); }, (errorResponse) => { pass = true; autoResetEvent.Set(); }, () => { autoResetEvent.Set(); }); }, (errorResponse) => { autoResetEvent.Set(); }, () => { autoResetEvent.Set(); }); autoResetEvent.WaitOne(); Assert.AreEqual(true, pass); }