/* * Function to attempt log in to a user account * @PARAMETERS: - song: the song to add * @RETURNS: The User who has been logged in - null if unsuccesful * @AUTHORS: Andrew Davis and Matt Malone * NOTE - Commented code left in by Matt - just in case it breaks */ public bool doInsertTrack(Song song, ISession session) { try { // Call to initialise cluster connection //init(); /// Guid tid = song.getSongID(); String artist = song.getArtist(); String album = song.getAlbum(); int year = song.getYear(); String genre = song.getGenre(); String file_loc = song.getFileLocation(); int length = song.getLength(); String trackname = song.getTrackName(); // Connect to cluster //ISession session = cluster.Connect("maltmusic"); //Guid tid = Guid.NewGuid(); // Prepare and bind statement passing in username String todo = ("insert into tracks (\n" + "track_id, artist, album, year,genre, file_loc,length,track_name)\n" + "values (:tid, :art,:alb,:yr,:gnr,:floc,:len,:tnm) if not exists"); PreparedStatement ps = session.Prepare(todo); BoundStatement bs = ps.Bind(tid, artist, album, year, genre, file_loc, length, trackname); // Execute Query session.Execute(bs); //session.Dispose(); return true; // Catch exceptions } catch (Exception ex) { Console.WriteLine("SOMETHING WENT WRONG in INSERT TRACK: " + ex.Message); return false; } }
//Plays the song the user selected private void lblPlay_Click(object sender, EventArgs e) { Song toAdd = new Song(); //Parse song String[] tmp = selectedSong.Split(','); int x = int.Parse(tmp[0]); int y = int.Parse(tmp[1]); String songName = songLabelsName[x][y].Text; for (int i = 0; i < songs.Count; i++) { if (songs[i].getTrackName().Equals(songName)) { toAdd = songs[i]; break; } } if (toAdd.getTrackName() != null && toAdd.getTrackName() != "") { //Stop currently playing song String filePath = toAdd.getFileLocation(); musicPlayer.stopSong(); //Load album art String imagePath = "../../tracks/" + toAdd.getArtist() + "/" + toAdd.getAlbum() + "/" + toAdd.getAlbum() + ".jpg"; //Send song to music player Playlist toPlay = new Playlist(); toPlay.addSongs(toAdd); musicPlayer.setPlaylist(toPlay, 0); musicPlayer.playCurrentSong(); } pnlOptions.Visible = false; }
//Adding song to playlist private void addSongToPlaylist(object sender, EventArgs e) { //Get the playlist int playListIndex; Label theLabel = (Label)sender; playListIndex = int.Parse(theLabel.Tag.ToString()); Playlist thePlaylist = usersPlaylists[playListIndex]; String[] tmp = selectedSong.Split(','); int x = int.Parse(tmp[0]); int y = int.Parse(tmp[1]); String songName = songLabelsName[x][y].Text; Song toAdd = new Song(); for (int i = 0; i < songs.Count; i++) { if (songs[i].getTrackName().Equals(songName)) { toAdd = songs[i]; break; } } //This part does the actual adding if (toAdd.getTrackName() != null && toAdd.getTrackName() != "") { PlaylistModel playlistModel = new PlaylistModel(); playlistModel.addSongToPlaylist(thePlaylist, toAdd); } pnlOptions.Visible = false; pnlPlaylists.Visible = false; }
//Play song in music player private void lblPlay_Click(object sender, EventArgs e) { //Get song Song toAdd = new Song(); String songName = songLabels[selectedSong].Text; for (int i = 0; i < songs.Count; i++) { if (songs[i].getTrackName().Equals(songName)) { toAdd = songs[i]; break; } } //Play in music player if (toAdd.getTrackName() != null && toAdd.getTrackName() != "") { //Get filepath of song, stop currently playing song String filePath = toAdd.getFileLocation(); musicPlayer.stopSong(); //Play song at path //String imagePath = "../../tracks/" + toAdd.getArtist() + "/" + toAdd.getAlbum() + "/" + toAdd.getAlbum() + ".jpg"; //musicPlayer.setSongPath(@"" + filePath, imagePath); musicPlayer.setPlaylist(thePlaylist, selectedSong); musicPlayer.playCurrentSong(); } pnlOptions.Visible = false; }
public void songAdded(Song song) { thePlaylist.addSongs(song); int count = thePlaylist.getSongs().Count - 1; #region Song Name Label Label theSongLabel = new Label(); theSongLabel.Text = song.getTrackName(); theSongLabel.Size = new Size(344, 30); theSongLabel.Location = new Point(423, 156 + (33 * count)); theSongLabel.Tag = count.ToString(); theSongLabel.UseMnemonic = false; theSongLabel.MouseEnter += hoverEvent; theSongLabel.MouseLeave += leaveEvent; theSongLabel.Click += setSelected; theSongLabel.ForeColor = Color.FromArgb(225, 225, 225); theSongLabel.TextAlign = ContentAlignment.MiddleLeft; theSongLabel.Font = new System.Drawing.Font("Franklin Gothic Medium", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); if (count % 2 == 0) { theSongLabel.BackColor = Color.FromArgb(60, 60, 60); } else { theSongLabel.BackColor = Color.FromArgb(40, 40, 40); } songLabels.Add(theSongLabel); this.Controls.Add(songLabels[count]); #endregion #region Position Label Label thePositionLabel = new Label(); thePositionLabel.Text = (count + 1).ToString(); thePositionLabel.Size = new Size(50, 30); thePositionLabel.Location = new Point(370, 156 + (33 * count)); thePositionLabel.Tag = count.ToString(); thePositionLabel.UseMnemonic = false; thePositionLabel.MouseEnter += hoverEvent; thePositionLabel.MouseLeave += leaveEvent; thePositionLabel.Click += setSelected; thePositionLabel.ForeColor = Color.FromArgb(225, 225, 225); thePositionLabel.TextAlign = ContentAlignment.MiddleLeft; thePositionLabel.Font = new System.Drawing.Font("Franklin Gothic Medium", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); if (count % 2 == 0) { thePositionLabel.BackColor = Color.FromArgb(60, 60, 60); } else { thePositionLabel.BackColor = Color.FromArgb(40, 40, 40); } positionLabels.Add(thePositionLabel); this.Controls.Add(positionLabels[count]); #endregion #region Artist Label LinkLabel theArtistLabel = new LinkLabel(); theArtistLabel.Text = songs[count].getArtist(); theArtistLabel.Size = new Size(250, 30); theArtistLabel.Location = new Point(770, 156 + (33 * count)); theArtistLabel.Tag = count.ToString(); theArtistLabel.UseMnemonic = false; theArtistLabel.MouseEnter += hoverEvent; theArtistLabel.MouseLeave += leaveEvent; theArtistLabel.Click += setSelected; theArtistLabel.LinkClicked += goToArtist; theArtistLabel.LinkColor = Color.White; theArtistLabel.VisitedLinkColor = Color.White; theArtistLabel.ForeColor = Color.FromArgb(225, 225, 225); theArtistLabel.TextAlign = ContentAlignment.MiddleLeft; theArtistLabel.Font = new System.Drawing.Font("Franklin Gothic Medium", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); if (count % 2 == 0) { theArtistLabel.BackColor = Color.FromArgb(60, 60, 60); } else { theArtistLabel.BackColor = Color.FromArgb(40, 40, 40); } artistLabels.Add(theArtistLabel); this.Controls.Add(artistLabels[count]); #endregion PictureBox removeIcon = new PictureBox(); removeIcon.Size = new Size(20, 20); removeIcon.Location = new Point(1025, 161 + (33 * count)); removeIcon.BackgroundImage = Properties.Resources.removeFromPlaylist; removeIcon.BackgroundImageLayout = ImageLayout.Stretch; removeIcon.Tag = count.ToString(); removeIcon.Click += removeSong; removeIcon.ForeColor = Color.FromArgb(225, 225, 225); removeLabels.Add(removeIcon); this.Controls.Add(removeLabels[count]); }