Пример #1
0
        private void BtnClearAllTracks_Click(object sender, EventArgs e)
        {
            DialogResult res = MessageBox.Show("Are you sure you want to delete all music?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (res == DialogResult.Yes)
            {
                sortedTrackList = new TrackLinkedList <string>();
                lbTracks.Items.Clear();
            }
            currentTrack = null;
            toolStripStatusLabel.Text = "All tracks cleared";
        }
Пример #2
0
 //method to add user selected files (of certain audio formats) to listbox
 //and to the linked list, while also sorting them with a merge sort
 private void BtnAddTracks_Click(object sender, EventArgs e)
 {
     //use open file dialog
     using (OpenFileDialog fileDialog = new OpenFileDialog()
     {
         Multiselect = true,
         //InitialDirectory = ".\",
         //accepted files types
         Filter = "WMA|*.wma|WMV|*.wmv|WAV|*wav|MP3|*.mp3|MP4|*.mp4|MKV|*.mkv"
     })
     {
         //if the user presses 'ok'
         if (fileDialog.ShowDialog() == DialogResult.OK)
         {
             //set the sorted track list to the unsorted - used if user add files multiple times
             //this serves to correct the node values of 'next' and 'prev' in the unsorted list
             trackList = sortedTrackList;
             //loop through the selected files and add as nodes to linked list
             foreach (string fileName in fileDialog.FileNames)
             {
                 //put this info into a file object
                 FileInfo file = new FileInfo(fileName);
                 //obtain path and name information as strings
                 string name = Path.GetFileNameWithoutExtension(file.FullName);
                 string path = file.FullName;
                 //if list isn't empty, check for dupes
                 if (trackList.GetLengthOfList() > 0)
                 {
                     Node <string> checkDupe = trackList.CheckForDuplicate(name);
                     if (checkDupe == null) //not not null, isnt added
                     {
                         //call add method
                         trackList.AddLastNode(name, path);
                     }
                 }
                 else
                 {
                     trackList.AddLastNode(name, path);
                 }
             }
             //null a new head object (useful if user adds files multiple times)
             Node <string> newHead = null;
             //set the new head object to the first place of the sorted list
             newHead = trackList.MergeSort(trackList.getHead());
             //clear the sorted list (in case of user adding songs multiple times)
             sortedTrackList = new TrackLinkedList <string>();
             //use a temp node object to traverse the sorted head nodes and store them in the sorted linked list
             Node <string> temp = newHead;
             while (temp != null)
             {
                 sortedTrackList.AddLastNode(temp.getName(), temp.getPath());
                 temp = temp.next;
             }
             //display sorted tracks in listBox
             DisplayTracks();
             //set current song to first in list
             currentTrack = newHead;
         }
     }
     toolStripStatusLabel.Text = "Success! Tracks have been added";
 }