diff --git a/MusicPlayer/MusicPlayer/Main.cs b/MusicPlayer/MusicPlayer/Main.cs index 14a2438..32b3c34 100644 --- a/MusicPlayer/MusicPlayer/Main.cs +++ b/MusicPlayer/MusicPlayer/Main.cs @@ -96,6 +96,9 @@ namespace MusicPlayer } action = () => { + imagelist.ImageSize = new System.Drawing.Size(64,64); + imagelist.ColorDepth = ColorDepth.Depth32Bit; + form.AlbumListView.View = View.LargeIcon; form.AlbumListView.LargeImageList = imagelist; foreach (ListViewItem item in form.AlbumListView.Items) { diff --git a/MusicPlayer/MusicPlayer/MainForm.Designer.cs b/MusicPlayer/MusicPlayer/MainForm.Designer.cs index a626738..026433e 100644 --- a/MusicPlayer/MusicPlayer/MainForm.Designer.cs +++ b/MusicPlayer/MusicPlayer/MainForm.Designer.cs @@ -31,7 +31,7 @@ namespace MusicPlayer private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); this.SongsTableView = new System.Windows.Forms.DataGridView(); this.GenreListBox = new System.Windows.Forms.ListBox(); @@ -86,6 +86,7 @@ namespace MusicPlayer this.RadioStationTextBox = new System.Windows.Forms.ToolStripTextBox(); this.SetRadioStationButton = new System.Windows.Forms.ToolStripMenuItem(); this.ControlsPanel = new System.Windows.Forms.Panel(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.NextButton = new System.Windows.Forms.Button(); this.PreviousButton = new System.Windows.Forms.Button(); this.CurrentSongLabel = new System.Windows.Forms.Label(); @@ -118,6 +119,7 @@ namespace MusicPlayer this.SplitContainer.SuspendLayout(); this.MenuStrip.SuspendLayout(); this.ControlsPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.PositionTrackBar)).BeginInit(); this.NotifyMenuStrip.SuspendLayout(); this.SuspendLayout(); @@ -129,14 +131,14 @@ namespace MusicPlayer this.SongsTableView.AllowUserToResizeRows = false; this.SongsTableView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; this.SongsTableView.BackgroundColor = System.Drawing.SystemColors.Control; - dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; - dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.ControlLight; - dataGridViewCellStyle1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText; - dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; - this.SongsTableView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1; + dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle4.BackColor = System.Drawing.SystemColors.ControlLight; + dataGridViewCellStyle4.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + dataGridViewCellStyle4.ForeColor = System.Drawing.SystemColors.WindowText; + dataGridViewCellStyle4.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle4.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.SongsTableView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle4; this.SongsTableView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.SongsTableView.Dock = System.Windows.Forms.DockStyle.Fill; this.SongsTableView.Location = new System.Drawing.Point(0, 0); @@ -444,7 +446,7 @@ namespace MusicPlayer this.SearchGenresTextBox, this.ClearGenreSearchButton}); this.SearchGenresToolStripLabel.Name = "SearchGenresToolStripLabel"; - this.SearchGenresToolStripLabel.Size = new System.Drawing.Size(152, 22); + this.SearchGenresToolStripLabel.Size = new System.Drawing.Size(127, 22); this.SearchGenresToolStripLabel.Text = "Genres"; // // SearchGenresTextBox @@ -467,7 +469,7 @@ namespace MusicPlayer this.SearchArtistsTextBox, this.ClearArtistSearchButton}); this.SearchArtistToolStripLabel.Name = "SearchArtistToolStripLabel"; - this.SearchArtistToolStripLabel.Size = new System.Drawing.Size(152, 22); + this.SearchArtistToolStripLabel.Size = new System.Drawing.Size(127, 22); this.SearchArtistToolStripLabel.Text = "Artists"; // // SearchArtistsTextBox @@ -490,7 +492,7 @@ namespace MusicPlayer this.SearchSongsTextBox, this.SearchSongsButton}); this.songsToolStripMenuItem.Name = "songsToolStripMenuItem"; - this.songsToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.songsToolStripMenuItem.Size = new System.Drawing.Size(127, 22); this.songsToolStripMenuItem.Text = "Songs"; // // SearchSongsTextBox @@ -509,12 +511,12 @@ namespace MusicPlayer // toolStripSeparator7 // this.toolStripSeparator7.Name = "toolStripSeparator7"; - this.toolStripSeparator7.Size = new System.Drawing.Size(149, 6); + this.toolStripSeparator7.Size = new System.Drawing.Size(124, 6); // // AdvancedSearchButton // this.AdvancedSearchButton.Name = "AdvancedSearchButton"; - this.AdvancedSearchButton.Size = new System.Drawing.Size(152, 22); + this.AdvancedSearchButton.Size = new System.Drawing.Size(127, 22); this.AdvancedSearchButton.Text = "Advanced"; this.AdvancedSearchButton.Click += new System.EventHandler(this.AdvancedSearchButton_Click); // @@ -611,6 +613,7 @@ namespace MusicPlayer // ControlsPanel // this.ControlsPanel.BackColor = System.Drawing.SystemColors.GrayText; + this.ControlsPanel.Controls.Add(this.pictureBox1); this.ControlsPanel.Controls.Add(this.NextButton); this.ControlsPanel.Controls.Add(this.PreviousButton); this.ControlsPanel.Controls.Add(this.CurrentSongLabel); @@ -628,9 +631,19 @@ namespace MusicPlayer this.ControlsPanel.Size = new System.Drawing.Size(784, 83); this.ControlsPanel.TabIndex = 4; // + // pictureBox1 + // + this.pictureBox1.BackColor = System.Drawing.SystemColors.Control; + this.pictureBox1.Location = new System.Drawing.Point(5, 5); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(72, 72); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; + this.pictureBox1.TabIndex = 14; + this.pictureBox1.TabStop = false; + // // NextButton // - this.NextButton.Location = new System.Drawing.Point(214, 51); + this.NextButton.Location = new System.Drawing.Point(295, 54); this.NextButton.Name = "NextButton"; this.NextButton.Size = new System.Drawing.Size(31, 23); this.NextButton.TabIndex = 13; @@ -640,7 +653,7 @@ namespace MusicPlayer // // PreviousButton // - this.PreviousButton.Location = new System.Drawing.Point(177, 51); + this.PreviousButton.Location = new System.Drawing.Point(258, 54); this.PreviousButton.Name = "PreviousButton"; this.PreviousButton.Size = new System.Drawing.Size(31, 23); this.PreviousButton.TabIndex = 12; @@ -651,7 +664,7 @@ namespace MusicPlayer // CurrentSongLabel // this.CurrentSongLabel.AutoSize = true; - this.CurrentSongLabel.Location = new System.Drawing.Point(256, 56); + this.CurrentSongLabel.Location = new System.Drawing.Point(338, 59); this.CurrentSongLabel.Name = "CurrentSongLabel"; this.CurrentSongLabel.Size = new System.Drawing.Size(111, 13); this.CurrentSongLabel.TabIndex = 11; @@ -670,7 +683,7 @@ namespace MusicPlayer // LabelCurrentTime // this.LabelCurrentTime.AutoSize = true; - this.LabelCurrentTime.Location = new System.Drawing.Point(12, 26); + this.LabelCurrentTime.Location = new System.Drawing.Point(93, 29); this.LabelCurrentTime.Name = "LabelCurrentTime"; this.LabelCurrentTime.Size = new System.Drawing.Size(49, 13); this.LabelCurrentTime.TabIndex = 8; @@ -681,10 +694,10 @@ namespace MusicPlayer this.PositionTrackBar.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.PositionTrackBar.Enabled = false; - this.PositionTrackBar.Location = new System.Drawing.Point(3, 3); + this.PositionTrackBar.Location = new System.Drawing.Point(83, 3); this.PositionTrackBar.Maximum = 1000; this.PositionTrackBar.Name = "PositionTrackBar"; - this.PositionTrackBar.Size = new System.Drawing.Size(778, 45); + this.PositionTrackBar.Size = new System.Drawing.Size(698, 45); this.PositionTrackBar.TabIndex = 7; this.PositionTrackBar.TickStyle = System.Windows.Forms.TickStyle.None; this.PositionTrackBar.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PositionTrackBar_MouseDown); @@ -710,7 +723,7 @@ namespace MusicPlayer // StopButton // this.StopButton.Enabled = false; - this.StopButton.Location = new System.Drawing.Point(122, 51); + this.StopButton.Location = new System.Drawing.Point(203, 54); this.StopButton.Name = "StopButton"; this.StopButton.Size = new System.Drawing.Size(49, 23); this.StopButton.TabIndex = 2; @@ -721,7 +734,7 @@ namespace MusicPlayer // PauseButton // this.PauseButton.Enabled = false; - this.PauseButton.Location = new System.Drawing.Point(67, 51); + this.PauseButton.Location = new System.Drawing.Point(148, 54); this.PauseButton.Name = "PauseButton"; this.PauseButton.Size = new System.Drawing.Size(49, 23); this.PauseButton.TabIndex = 1; @@ -731,7 +744,7 @@ namespace MusicPlayer // // PlayButton // - this.PlayButton.Location = new System.Drawing.Point(12, 51); + this.PlayButton.Location = new System.Drawing.Point(93, 54); this.PlayButton.Name = "PlayButton"; this.PlayButton.Size = new System.Drawing.Size(49, 23); this.PlayButton.TabIndex = 0; @@ -863,6 +876,7 @@ namespace MusicPlayer this.MenuStrip.PerformLayout(); this.ControlsPanel.ResumeLayout(false); this.ControlsPanel.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.PositionTrackBar)).EndInit(); this.NotifyMenuStrip.ResumeLayout(false); this.ResumeLayout(false); @@ -949,6 +963,7 @@ namespace MusicPlayer private System.Windows.Forms.ToolStripSeparator toolStripSeparator7; private System.Windows.Forms.ToolStripMenuItem AdvancedSearchButton; private System.Windows.Forms.ToolStripMenuItem resetToolStripMenuItem; + private System.Windows.Forms.PictureBox pictureBox1; } } diff --git a/MusicPlayer/MusicPlayer/MainForm.cs b/MusicPlayer/MusicPlayer/MainForm.cs index 8610fb5..6609580 100644 --- a/MusicPlayer/MusicPlayer/MainForm.cs +++ b/MusicPlayer/MusicPlayer/MainForm.cs @@ -110,8 +110,15 @@ namespace MusicPlayer CurrentSongLabel.Text = "Currently playing: " + main.audio.CurrentSong.Name; } - //Buttons and context menu - if (main.audio.AState == AudioHandler.AudioState.PLAYING) + //image box + if (AlbumListView.LargeImageList != null && main.audio.CurrentSong != null) + { + //Console.WriteLine(AlbumListView.LargeImageList.Images["Get Wet"]); + pictureBox1.Image = AlbumListView.LargeImageList.Images[main.audio.CurrentSong.Album]; + } + + //Buttons and context menu + if (main.audio.AState == AudioHandler.AudioState.PLAYING) { PlayButton.Enabled = false; NotifyMenuStripPlayButton.Enabled = false; diff --git a/MusicPlayer/MusicPlayer/Playlist.cs b/MusicPlayer/MusicPlayer/Playlist.cs index d009a98..a75fadc 100644 --- a/MusicPlayer/MusicPlayer/Playlist.cs +++ b/MusicPlayer/MusicPlayer/Playlist.cs @@ -71,5 +71,21 @@ namespace MusicPlayer stw.Flush(); } } + + public void Delete() + { + try { + System.IO.File.Move(basedir + name + ".txt", basedir + name + ".txt.old"); + } + catch(Exception) + { + //Already removed. + } + } + + internal void RemoveSong(Song s) + { + this.songs.Remove(s); + } } } \ No newline at end of file diff --git a/MusicPlayer/MusicPlayer/PlaylistHandler.cs b/MusicPlayer/MusicPlayer/PlaylistHandler.cs index 8b151a0..b6fbf90 100644 --- a/MusicPlayer/MusicPlayer/PlaylistHandler.cs +++ b/MusicPlayer/MusicPlayer/PlaylistHandler.cs @@ -20,6 +20,8 @@ namespace MusicPlayer public void Populate() { + playlists.Clear(); + try { Directory.GetFiles(basedir).ToList().ForEach(f => { @@ -63,5 +65,20 @@ namespace MusicPlayer } return currentPlaylists; } + + internal void RemovePlaylistByName(string name) + { + Playlist toRemove = null; + playlists.ForEach(p => + { + if (p.name == name) { toRemove = p; } + }); + + if(toRemove != null) + { + toRemove.Delete(); + playlists.Remove(toRemove); + } + } } } \ No newline at end of file diff --git a/MusicPlayer/MusicPlayer/PlaylistMaker.Designer.cs b/MusicPlayer/MusicPlayer/PlaylistMaker.Designer.cs index 5fa3ff3..dfffd4c 100644 --- a/MusicPlayer/MusicPlayer/PlaylistMaker.Designer.cs +++ b/MusicPlayer/MusicPlayer/PlaylistMaker.Designer.cs @@ -43,6 +43,8 @@ namespace MusicPlayer this.label4 = new System.Windows.Forms.Label(); this.FilterTextBox = new System.Windows.Forms.TextBox(); this.label5 = new System.Windows.Forms.Label(); + this.DeletePlaylistButton = new System.Windows.Forms.Button(); + this.DeleteSongsButton = new System.Windows.Forms.Button(); this.SuspendLayout(); // // PlaylistSelectBox @@ -87,6 +89,7 @@ namespace MusicPlayer this.PlaylistSongContainer.FormattingEnabled = true; this.PlaylistSongContainer.Location = new System.Drawing.Point(10, 319); this.PlaylistSongContainer.Name = "PlaylistSongContainer"; + this.PlaylistSongContainer.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended; this.PlaylistSongContainer.Size = new System.Drawing.Size(306, 82); this.PlaylistSongContainer.TabIndex = 3; // @@ -123,7 +126,7 @@ namespace MusicPlayer // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(10, 80); + this.label2.Location = new System.Drawing.Point(8, 75); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(97, 13); this.label2.TabIndex = 7; @@ -133,7 +136,7 @@ namespace MusicPlayer // this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(7, 303); + this.label3.Location = new System.Drawing.Point(11, 297); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(82, 13); this.label3.TabIndex = 8; @@ -165,11 +168,35 @@ namespace MusicPlayer this.label5.TabIndex = 11; this.label5.Text = "Filter"; // + // DeletePlaylistButton + // + this.DeletePlaylistButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.DeletePlaylistButton.Location = new System.Drawing.Point(225, 70); + this.DeletePlaylistButton.Name = "DeletePlaylistButton"; + this.DeletePlaylistButton.Size = new System.Drawing.Size(92, 23); + this.DeletePlaylistButton.TabIndex = 12; + this.DeletePlaylistButton.Text = "Delete Playlist"; + this.DeletePlaylistButton.UseVisualStyleBackColor = true; + this.DeletePlaylistButton.Click += new System.EventHandler(this.DeletePlaylistButton_Click); + // + // DeleteSongsButton + // + this.DeleteSongsButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.DeleteSongsButton.Location = new System.Drawing.Point(172, 292); + this.DeleteSongsButton.Name = "DeleteSongsButton"; + this.DeleteSongsButton.Size = new System.Drawing.Size(143, 23); + this.DeleteSongsButton.TabIndex = 13; + this.DeleteSongsButton.Text = "Delete Selected Songs"; + this.DeleteSongsButton.UseVisualStyleBackColor = true; + this.DeleteSongsButton.Click += new System.EventHandler(this.DeleteSongsButton_Click); + // // PlaylistMaker // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(334, 411); + this.Controls.Add(this.DeleteSongsButton); + this.Controls.Add(this.DeletePlaylistButton); this.Controls.Add(this.label5); this.Controls.Add(this.FilterTextBox); this.Controls.Add(this.label4); @@ -206,5 +233,7 @@ namespace MusicPlayer private Label label4; private TextBox FilterTextBox; private Label label5; + private Button DeletePlaylistButton; + private Button DeleteSongsButton; } } \ No newline at end of file diff --git a/MusicPlayer/MusicPlayer/PlaylistMaker.cs b/MusicPlayer/MusicPlayer/PlaylistMaker.cs index bd4a079..5267b6f 100644 --- a/MusicPlayer/MusicPlayer/PlaylistMaker.cs +++ b/MusicPlayer/MusicPlayer/PlaylistMaker.cs @@ -47,12 +47,17 @@ namespace MusicPlayer PlaylistSelectBox.SelectedIndex = PlaylistSelectBox.Items.Count - 1; else PlaylistSelectBox.SelectedIndex = selection; + PlaylistSongContainer.Items.Clear(); if (PlaylistSelectBox.SelectedItem != null) { - PlaylistSongContainer.Items.Clear(); allPlaylistSongs = pl.GetPlaylistByName(PlaylistSelectBox.SelectedItem.ToString()).GetSongs(); allPlaylistSongs.ForEach(s => PlaylistSongContainer.Items.Add(s.Name)); } + else + { + PlaylistSelectBox.SelectedIndex = -1; + PlaylistSelectBox.Text = ""; + } } public void Repopulate() @@ -145,5 +150,38 @@ namespace MusicPlayer PlaylistNewButton_Click(sender, new EventArgs()); } } + + private void DeletePlaylistButton_Click(object sender, EventArgs e) + { + if (PlaylistSelectBox.SelectedItem != null) + if (MessageBox.Show("Are you sure to delete " + PlaylistSelectBox.SelectedItem.ToString() + "?", "Confirm Delete!", MessageBoxButtons.YesNo) == DialogResult.Yes) + { + pl.RemovePlaylistByName(PlaylistSelectBox.SelectedItem.ToString()); + Repopulate(true); + } + } + + private void DeleteSongsButton_Click(object sender, EventArgs e) + { + if (PlaylistSelectBox.SelectedItem != null) + { + Playlist currentPlaylist = pl.GetPlaylistByName(PlaylistSelectBox.SelectedItem.ToString()); + foreach (string song in PlaylistSongSelector.SelectedItems) + { + for (int i = currentPlaylist.GetSongs().Count - 1; i > 0; i--) + { + Song s = currentPlaylist.GetSongs()[i]; + if (s.Name == song) + { + currentPlaylist.RemoveSong(s); + break; + } + } + } + currentPlaylist.WriteToFile(); + } + Thread.Sleep(10); + Repopulate(); + } } } diff --git a/MusicPlayer/MusicPlayer/Program.cs b/MusicPlayer/MusicPlayer/Program.cs index 6e1e41d..8e238a2 100644 --- a/MusicPlayer/MusicPlayer/Program.cs +++ b/MusicPlayer/MusicPlayer/Program.cs @@ -17,7 +17,6 @@ namespace MusicPlayer Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); -// NetworkHandler nw = new NetworkHandler("http://jancokock.me"); NetworkHandler nw = new NetworkHandler("http://imegumii.nl"); APIHandler api = new APIHandler(nw); MainForm form = new MainForm(); diff --git a/MusicPlayer/MusicPlayer/Song.cs b/MusicPlayer/MusicPlayer/Song.cs index 59e87d4..10d6798 100644 --- a/MusicPlayer/MusicPlayer/Song.cs +++ b/MusicPlayer/MusicPlayer/Song.cs @@ -53,5 +53,29 @@ namespace MusicPlayer { return $"{this.SongID}|{this.Name}|{this.Album}|{this.Artist}|{this.Genre}|{this.Seconds}"; } + + public override bool Equals(System.Object obj) + { + // If parameter is null return false. + if (obj == null) + { + return false; + } + + // If parameter cannot be cast to Point return false. + Song s = obj as Song; + if ((System.Object)s == null) + { + return false; + } + + // Return true if the fields match: + return (s.Name == Name) && (s.SongID == SongID); + } + + public override int GetHashCode() + { + return int.Parse(this.SongID); + } } }