// Adds videos to Playlist given a browser URL private bool AddToPlaylist(string url) { if (IsYoutubeURL(url)) { if (url.Contains("&")) { url = url.Substring(0, url.IndexOf('&')); } PlaylistURLs.Add(ConvertURLToEmbeded(url)); Video video = RequestFromYoutube(url); Playlist.Items.Add(video.Snippet.Title); UpdatePlaylistCount(); if (Hosting) { Broadcast("has added " + video.Snippet.Title + " to the playlist", NicknameLabel.Text, false); BroadcastPlaylist(); } else { BroadcastPlaylist("has added " + video.Snippet.Title + " to the playlist"); } return(true); } else { return(false); } }
// Called from inside non-main thread thus invoke required. Updates the playlist when new list info is had. private void PlaylistUpdate(string[] Message) { if (this.InvokeRequired) { try { this.Invoke(new Action <string[]>(PlaylistUpdate), new object[] { Message }); } catch { return; } } else { string CurrentVideoName = "Nothing"; int CurrentVideoIndex = 0; int NewVideoIndex = 0; if (PlaylistURLs.Count > 0 && CurrentlyPlaying > -1) { CurrentVideoName = PlaylistURLs[CurrentlyPlaying]; CurrentVideoIndex = CurrentlyPlaying; NewVideoIndex = 0; } List <string> NewPlaylistURLs = new List <string>(); List <string> NewPlaylistTitles = new List <string>(); for (int i = 1; i < Message.Length - 1; i++) { NewPlaylistURLs.Add(Message[i]); if (!PlaylistURLs.Contains(Message[i])) { Video video = RequestFromYoutube(ConvertURLToBrowser(Message[i])); NewPlaylistTitles.Add(video.Snippet.Title); } else { NewPlaylistTitles.Add(Playlist.Items[PlaylistURLs.IndexOf(Message[i])].ToString()); } } PlaylistURLs = NewPlaylistURLs; Playlist.Items.Clear(); foreach (string s in NewPlaylistTitles) { Playlist.Items.Add(s); } PlaylistLabel.Text = "Playlist Count: " + Playlist.Items.Count; if (PlaylistURLs.Count > 0 && CurrentlyPlaying > -1) { for (int i = 0; i < PlaylistURLs.Count; i++) { if (PlaylistURLs[i] == CurrentVideoName) { NewVideoIndex = i; } } CurrentlyPlaying = NewVideoIndex; Playlist.Refresh(); } } }
// Called in order to remove a video from the playlist given an index private void DeleteVideo(int Index) { string Title = Playlist.Items[Index].ToString(); PlaylistURLs.RemoveAt(Index); Playlist.Items.RemoveAt(Index); UpdatePlaylistCount(); if (Hosting) { Broadcast("has removed " + Title + " from the playlist", NicknameLabel.Text, false); BroadcastPlaylist(); } else { BroadcastPlaylist("has removed " + Title + " from the playlist"); } Thread.Sleep(100); if (Index == CurrentlyPlaying) { if (PlaylistURLs.Count <= Index && PlaylistURLs.Count != 0) { PlayVideo(PlaylistURLs.Count - 1, false); } else if (PlaylistURLs.Count == 0) { YoutubeVideo.Movie = null; } else { PlayVideo(CurrentlyPlaying, false); } } else if (Index < CurrentlyPlaying) { CurrentlyPlaying--; Playlist.Refresh(); } }