private void bPlayAndRecord_Click(object sender, EventArgs e) { if (dgvPlaylists.CurrentRow.Index < 0) { return; } thisPlayList = playlists.Items[dgvPlaylists.CurrentRow.Index]; lastTrack1 = null; lastTrack2 = null; for (int t = 0; t < playlist.Items.Count; t++) { error = spotify.ResumePlayback(contextUri: "spotify:user:"******":playlist:" + thisPlayList.Id, offset: t); if (whichFile == 1) { thisTrack1 = playlist.Items[t].Track; Thread tRecord = new Thread(RecordTrack); tRecord.Start(); tRecord.Join(); } else { thisTrack2 = playlist.Items[t].Track; Thread tRecord = new Thread(RecordTrack); tRecord.Start(); tRecord.Join(); } } }
public async void SetPlaylist(SimplePlaylist playlist) { _playlist = playlist; // Add loading spinner on main thread if (_loadSpinnerPrefab != null) { _dispatcher.Add(() => { _instLoadSpinner = Instantiate(_loadSpinnerPrefab, _tracksListParent); }); } SpotifyClient client = SpotifyService.Instance.GetSpotifyClient(); // Get full details of simple playlist _fullPlaylist = await client.Playlists.Get(_playlist.Id); // Get all tracks inside full playlist _allTracks = await GetAllTracks(client); // Require ui update on main thread _dispatcher.Add(() => { UpdateUI(); if (_instLoadSpinner != null) { Destroy(_instLoadSpinner); } }); }
private void addSongButton_Click(object sender, EventArgs e) { if (_spotifyWebAPI == null || _profile == null) { return; } if (searchView.SelectedItems.Count == 0) { return; } ListViewItem selectedSong = searchView.SelectedItems[0]; if (selectedSong == null) { return; } string songURL = selectedSong.Tag as string; if (songURL == "") { return; } SimplePlaylist selectedPlaylist = (SimplePlaylist)playlistListbox.SelectedItem; List <string> tracks = new List <string>(); for (int i = 0; i < addSongCount.Value; i++) { tracks.Add(songURL); } ErrorResponse error = _spotifyWebAPI.AddPlaylistTracks(_profile.Id, selectedPlaylist.Id, tracks); }
public static async Task <SimplePlaylist> getPlayListById(string id) { var json = await File.ReadAllTextAsync(CredentialsPath); var token = JsonConvert.DeserializeObject <PKCETokenResponse>(json); var authenticator = new PKCEAuthenticator(clientId !, token); authenticator.TokenRefreshed += (sender, token) => File.WriteAllText(CredentialsPath, JsonConvert.SerializeObject(token)); var config = SpotifyClientConfig.CreateDefault() .WithAuthenticator(authenticator); var spotify = new SpotifyClient(config); var me = await spotify.UserProfile.Current(); var playlists = await spotify.PaginateAll(await spotify.Playlists.CurrentUsers().ConfigureAwait(false)); SimplePlaylist item = null; foreach (SimplePlaylist list_item in playlists) { if (list_item.Id == id) { item = list_item; break; } } _server.Dispose(); return(item); }
// TODO: handle AC/DC splitting //private readonly Hashtable<IReadOnlyList<string>, string> public PlaylistBase ToSimplePlaylist( Func <uint> newPlaylistIdGenerator, uint?parentPlaylistId, ITracksRepository tracksRepository, IReadOnlyDictionary <uint, Track> tracksMapper) { PlaylistBase playlist = null; try { playlist = new SimplePlaylist( newPlaylistIdGenerator.Invoke(), // library entry parentPlaylistId, this.Name, tracksRepository, tracksMapper == null || this.Playlist_Items == null ? ImmutableList <uint> .Empty : this.Playlist_Items.Select(x => tracksMapper[x].Id).ToImmutableList()); } catch //(Exception ex) { playlist = null; } return(playlist); }
private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { SimplePlaylist item = (SimplePlaylist)listBox1.SelectedItem; labelPlaylistName.Text = item.Name; labelPlaylistOwner.Text = item.Owner.DisplayName; labelPlaylistTotal.Text = item.Tracks.Total.ToString(); listBox2.Items.Clear(); var playlists = spotify.GetPlaylistTracks(item.Id); while (true) { foreach (var s in playlists.Items) { listBox2.Items.Add(s.Track); } if (playlists.HasNextPage()) { playlists = spotify.GetPlaylistTracks(item.Id, offset: playlists.Offset + 100); } else { break; } } listBox2.ValueMember = "Id"; listBox2.DisplayMember = "Name"; }
public static async Task PlayPlaylist(SimplePlaylist playlist) { var json = await File.ReadAllTextAsync(CredentialsPath); var token = JsonConvert.DeserializeObject <PKCETokenResponse>(json); var authenticator = new PKCEAuthenticator(clientId !, token); authenticator.TokenRefreshed += (sender, token) => File.WriteAllText(CredentialsPath, JsonConvert.SerializeObject(token)); var config = SpotifyClientConfig.CreateDefault() .WithAuthenticator(authenticator); var spotify = new SpotifyClient(config); var me = await spotify.UserProfile.Current(); PlayerResumePlaybackRequest teste = new PlayerResumePlaybackRequest(); teste.ContextUri = playlist.Uri; await spotify.Player.ResumePlayback(teste); _server.Dispose(); // Environment.Exit(0); }
private void AddTracksFromPlaylistToPlaylis(User user, SimplePlaylist playlist) { Extensions.WriteColoredConsole( $"Begin adding tracks from \"{user.Name}\"s \"{playlist.Name}\" to \"{_config.TargetPlaylist.Name}\"", ConsoleColor.Cyan); AddTracksFromPlaylistToPlaylist(playlist.Owner.Id, playlist.Id, _config.TargetPlaylist.Owner.Identifier, _config.TargetPlaylist.Identifier, user.Name); }
public void AddWithEmptyShouldThrowArgumentNullException() { // Arrange var playlist = new SimplePlaylist(); string item = string.Empty; // Act & Assert Assert.Throws <ArgumentNullException>(() => playlist.Add(item)); }
private void PlaylistTab_VisibleChanged(object sender, EventArgs e) { if (!this.Visible) { this.treeView.Nodes["NodePlaylist"].Nodes.Clear(); this.imageList.Images.Clear(); this.lblStatus.Visible = false; return; } else { if (System.IO.Directory.Exists(Paths.PlaylistFolder)) { savedPlaylists = SimplePlaylist <Song> .LoadFromDirectory(Paths.PlaylistFolder).ToList(); } int count = 0; if (savedPlaylists != null) { this.imageList.Images.Add(Resources.MailArr); this.imageList.Images.Add(Resources.SimplePl); this.imageList.Images.Add(Resources.AutoPlaylist); this.treeView.ImageList = this.imageList; this.treeView.Nodes["NodePlaylist"].ImageIndex = 0; foreach (var playlist in savedPlaylists) { var node = this.treeView.Nodes["NodePlaylist"].Nodes.Add(playlist.Name); node.ImageIndex = 1; node.SelectedImageIndex = 1; } count = savedPlaylists.Count; } if (System.IO.Directory.Exists(Paths.AutomaticPlaylistFolder)) { savedPlaylists.AddRange(AutoPlaylist <Song> .LoadFromDirectory(Paths.AutomaticPlaylistFolder)); } if (savedPlaylists != null) { for (int i = count; i < savedPlaylists.Count; i++) { var node = this.treeView.Nodes["NodePlaylist"].Nodes.Add(savedPlaylists[i].Name); node.ImageIndex = 2; node.SelectedImageIndex = 2; } } this.treeView.SelectedNode = this.treeView.Nodes["NodePlaylist"]; this.treeView.Select(); this.treeView.ExpandAll(); } }
public void AddArrayWithEmptyItemShouldThrowArgumentException() { // Arrange var playlist = new SimplePlaylist(); string[] items = { "file01.mp3", string.Empty, "file03.mp3" }; // Act & Assert Assert.Throws <ArgumentException>(() => playlist.Add(items)); }
public void AddArrayWithNullShouldThrowArgumentNullException() { // Arrange var playlist = new SimplePlaylist(); string[] items = null; // Act & Assert Assert.Throws <ArgumentNullException>(() => playlist.Add(items)); }
public void ConstructorShoulInitializePlaylist() { // Arrange SimplePlaylist playlist; // Act playlist = new SimplePlaylist(); // Assert Assert.Equal(0, playlist.Count); }
public void GetNextSongWithEmptyPlaylistShouldReturnStringEmpty() { // Arrange var playlist = new SimplePlaylist(); string nextSongPath; // Act nextSongPath = playlist.GetNextSongPath(); // Assert Assert.Equal(string.Empty, nextSongPath); }
public void AddWithArrayShouldAddElementsToCollection() { // Arrange var playlist = new SimplePlaylist(); var items = new [] { "file01.mp3", "file02.mp3", "file03.mp3" }; // Act playlist.Add(items); // Assert Assert.Equal(3, playlist.Count); }
public void GetPreviousSongPathWithEmptyPlaylistShouldReturnStringEmpty() { // Arrange var playlist = new SimplePlaylist(); string previousSongPath = "dummy-value"; // Act previousSongPath = playlist.GetPreviousSongPath(); // Assert Assert.Equal(string.Empty, previousSongPath); }
public void CountWithEmptyEmptyPlaylistShouldReturnZero() { // Arrange var playlist = new SimplePlaylist(); int count; // Act count = playlist.Count; // Assert Assert.Equal(0, count); }
public void ClearWithEmptyPlaylistShouldDoNothing() { // Arrange var playlist = new SimplePlaylist(); string currentSongPath; // Act playlist.Clear(); currentSongPath = playlist.GetCurrentSongPath(); // Assert Assert.Equal(string.Empty, currentSongPath); }
public void GetPreviousSongPathWithOneItemShouldReturnStringEmpty() { // Arrange var playlist = new SimplePlaylist(); playlist.Add(@"C:\music\song.mp3"); string previousSongPath; // Act previousSongPath = playlist.GetPreviousSongPath(); // Assert Assert.Equal(string.Empty, previousSongPath); }
public static void SelectItemByValue(this ComboBox cbo, SimplePlaylist playlist) { if (playlist != null) { foreach (GlobalControlSpotifyPlayList item in cbo.Items) { if (item.Value.Id == playlist.Id) { cbo.SelectedItem = item; break; } } } }
/// <summary> /// Get the songs of the playlist under supervision as ListView items. /// </summary> /// <param name="playlistId">The ID of the playlist under supervision.</param> /// <returns>The songs of the playlist under supervision as ListView items.</returns> public List <ListViewItem> getSongsOfPlaylistAsStrings(int playlistId) { List <ListViewItem> theSongs = new List <ListViewItem>(); SimplePlaylist thePlaylist = _playlists.ElementAt(playlistId); _spotifyTrackSet = new List <PlaylistTrack>(); Paging <PlaylistTrack> tracks = _spotifyAPI.GetPlaylistTracks(_profile.Id, thePlaylist.Id); if (tracks.Items != null) { int i = 100; while (true) { Paging <PlaylistTrack> temp = _spotifyAPI.GetPlaylistTracks(_profile.Id, thePlaylist.Id, "", 100, i); if (temp != null && temp.Items != null && temp.Items.Count > 0) { foreach (PlaylistTrack playTrack in temp.Items) { tracks.Items.Add(playTrack); } i += 100; } else { break; } } foreach (PlaylistTrack track in tracks.Items) { if (track != null) { _spotifyTrackSet.Add(track); } } } foreach (PlaylistTrack track in _spotifyTrackSet) { ListViewItem theItem = new ListViewItem(new string[] { track.Track.Name, track.Track.Artists[0].Name, track.Track.Album.Name }); theItem.ImageIndex = 0; theSongs.Add(theItem); } return(theSongs); }
public void GetCurrentSongWithOneItemShouldReturnItem() { // Arrange var playlist = new SimplePlaylist(); var song01 = @"C:\music\song01.mp3"; playlist.Add(song01); string currentSongPath; // Act currentSongPath = playlist.GetCurrentSongPath(); // Assert Assert.Equal(song01, currentSongPath); }
public void GetNextSongShouldReturnNextItem() { // Arrange var playlist = new SimplePlaylist(); var song01 = @"C:\music\song01.mp3"; var song02 = @"C:\music\song02.mp3"; playlist.Add(song01); playlist.Add(song02); string nextSongPath; // Act nextSongPath = playlist.GetNextSongPath(); // Assert Assert.Equal(song02, nextSongPath); }
public void GetPreviousSongPathSecondCallWithTwoItemsShouldReturnStringEmpty() { // Arrange var playlist = new SimplePlaylist(); playlist.Add(@"C:\music\song01.mp3"); playlist.Add(@"C:\music\song02.mp3"); playlist.GetNextSongPath(); string previousSongPath; // Act playlist.GetPreviousSongPath(); previousSongPath = playlist.GetPreviousSongPath(); // Assert Assert.Equal(string.Empty, previousSongPath); }
public void CountWithPlaylistWithItemsShouldReturnPlaylistItemCount() { // Arrange var playlist = new SimplePlaylist(); var song01 = @"C:\music\song01.mp3"; var song02 = @"C:\music\song02.mp3"; playlist.Add(song01); playlist.Add(song02); int count; // Act count = playlist.Count; // Assert Assert.Equal(2, count); }
public void GetPreviousSongPathWithMoreThanOneItemShouldReturnPreviousItem() { // Arrange var playlist = new SimplePlaylist(); var song01 = @"C:\music\song01.mp3"; playlist.Add(song01); playlist.Add(@"C:\music\song02.mp3"); playlist.GetNextSongPath(); string previousSongPath; // Act previousSongPath = playlist.GetPreviousSongPath(); // Assert Assert.Equal(song01, previousSongPath); }
public void ClearWithItemsShouldClearPlaylist() { // Arrange var playlist = new SimplePlaylist(); var song01 = @"C:\music\song01.mp3"; var song02 = @"C:\music\song02.mp3"; playlist.Add(song01); playlist.Add(song02); string currentSongPath; // Act playlist.Clear(); currentSongPath = playlist.GetCurrentSongPath(); // Assert Assert.Equal(string.Empty, currentSongPath); }
private void LoadPlaylist() { SimplePlaylist <Song> simpleplaylist = SimplePlaylist <Song> .LoadFromFile(Paths.CurrentPlaylist + "currentPLaudio.txt"); var mediaList = simpleplaylist.Media.ToArray(); this.audioListBox.BeginUpdate(); for (int i = 0; i < simpleplaylist.Count; i++) { Song media = mediaList[i]; Song song = this.bal.GetSongByFilename(media.Filename); this.audioListBox.Items.Add(song); } this.audioListBox.EndUpdate(); SimplePlaylist <Picture> simpleplaylist1 = SimplePlaylist <Picture> .LoadFromFile(Paths.CurrentPlaylist + "currentPLpicture.txt"); this.imageListBox.BeginUpdate(); var mediaList1 = simpleplaylist1.Media.ToArray(); for (int i = 0; i < simpleplaylist1.Count; i++) { var media = mediaList1[i]; Picture p = SharedData.Database.Picture.FindByFilename(media.Filename); if (p != null) { this.imageListBox.Items.Add(p); } } this.imageListBox.EndUpdate(); if (Settings.Default.PlayAtStartUp && audioListBox.Items.Count > 0) { audioListBox.SelectedIndex = 0; this.PlaySelectedMedia(); Settings.Default.PlayAtStartUp = false; Settings.Default.Save(); } }
public async void SetupKicked() { string KickedName = $"Kicked Out {DateTime.Now.Year}"; Paging <SimplePlaylist> playlists = await spotify.Playlists.CurrentUsers(); KickedPlaylist = playlists.Items.Find(x => x.Name == KickedName); if (KickedPlaylist == null) { FullPlaylist playlist = await spotify.Playlists.Create((await spotify.UserProfile.Current()).Id, new PlaylistCreateRequest(KickedName)); SetupKicked(); } else { KickedTracks = (await spotify.Playlists.GetItems(KickedPlaylist.Id)).Items; } }
public static void SavePlaylist <T>(this SimplePlaylist <T> itemSet, string name, T[] items) where T : class, IStronglyTraceable <int>, IMedia, new() { Shauni.Playlist.SimplePlaylist <T> simpleplaylist = new Shauni.Playlist.SimplePlaylist <T>(name, null); if (items.Length > 0) { try { simpleplaylist.AddMoreMedia(items.Cast <T>().ToArray()); simpleplaylist.SaveToFile(Paths.CurrentPlaylist); } catch { } } else // bug when wmp is playing, or is open { string filename = Paths.CurrentPlaylist + name + ".txt"; File.WriteAllText(filename, ""); //bug due to the non-generic format provider. Maybe it is fixed... } }