Beispiel #1
0
        /*
         * 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;
        }
        //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;
        }
        /// <summary>
        /// Acquires the file path of the song via the playlist
        /// </summary>
        /// <returns>The file location of the song</returns>
        private string getNextSong()
        {
            // Acquires the song
            thisSong = activePlaylist.getSongByID(playlistIndex);

            // Get and the album artwork
            string imagePath = thisSong.getImagePath();

            // Sets the album art image
            try
            {
                picBoxAlbumArt.Image = Image.FromFile(imagePath);
            }catch(FileNotFoundException){
                picBoxAlbumArt.Image = MALT_Music.Properties.Resources.logo;
            }

            // Acquires the path
            string songPath = thisSong.getFileLocation();

            return songPath;
        }