/// <summary> /// Plays an AccountSong. /// </summary> /// <param name="accountSong">Account song to play</param> public void PlayAccountSong(AccountSong accountSong) { if (LatestAccountSongPlayed != null) { if (Session.SongsIdPlayHistory.Count == Core.MAX_SONGS_IN_HISTORY) { Session.SongsIdPlayHistory.RemoveAt(0); } Session.SongsIdPlayHistory.Add(LatestAccountSongPlayed.AccountSongId * -1); } if (LatestSongPlayed != null) { if (Session.SongsIdPlayHistory.Count == Core.MAX_SONGS_IN_HISTORY) { Session.SongsIdPlayHistory.RemoveAt(0); } Session.SongsIdPlayHistory.Add(LatestSongPlayed.SongId); } LatestSongPlayed = null; if (LatestAccountSongPlayed != null && LatestAccountSongPlayed.AccountSongId == accountSong.AccountSongId) { PlayMemoryStream(new MemoryStream(latestStream.ToArray()), false); return; } LatestAccountSongPlayed = accountSong; songNameTextBlock.Text = accountSong.Title; artistNameTextBlock.Text = ""; MakeRequestStreamSong(Core.SERVER_API_URL + "/stream/accountsong/" + accountSong.AccountSongId); likeButton.Visibility = Visibility.Hidden; dislikeButton.Visibility = Visibility.Hidden; }
/// <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> /// Plays the double clicked account song. /// </summary> /// <param name="sender">DataGridCell</param> /// <param name="e">Event</param> public static void AccountSongTable_OnDoubleClick(object sender, MouseButtonEventArgs e) { IInputElement element = e.MouseDevice.DirectlyOver; if (element is FrameworkElement && ((FrameworkElement)element).Parent is DataGridCell) { var grid = sender as DataGrid; if (grid != null && grid.SelectedItems != null && grid.SelectedItems.Count == 1) { var accountSongRow = (AccountSongTable)grid.SelectedItem; AccountSong accountSong = accountSongRow.AccountSong; Session.PlayerPage.ShouldPlayNextSong = false; Session.PlayerPage.PlayAccountSong(accountSong); } } }
/// <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); }