private static void CreateSongStructure(ref XElement rootElement, SongLoc songLocation)
        {
            try
            {
                string name = songLocation.Name;
                XElement songElement = new XElement("song", new XAttribute("Name", songLocation.Name));

                songElement.Value = songLocation.Location;
                rootElement.Add(songElement);

            }
            catch(Exception ex)
            {
                Console.WriteLine("Songs not added - " + songLocation.Name);
            }
        }
Example #2
0
 public void Add(SongLoc item)
 {
     _listOfSongs.Add(item);
 }
        private static void FindSongs(string path, ref SongLocations songs)
        {
            if (Directory.Exists(path))
            {
                string[] files = null;
                try
                {
                    files = Directory.GetFiles(path);
                }
                catch(UnauthorizedAccessException ex)
                {
                }
                if (files != null)
                {
                    foreach (string file in files)
                    {
                        FileInfo fileInfo = new FileInfo(file);
                        if ((fileInfo.Extension.Equals(".mp3")) || (fileInfo.Extension.Equals(".MP3")))
                        {
                            TagLib.File tagFile = null;

                            SongLoc song = new SongLoc();
                            try
                            {
                                tagFile = new TagLib.Aac.File(file);
                            }
                            catch { }

                            string songName = null;
                            if (tagFile != null)
                                songName = tagFile.Tag.Title;
                            else
                                songName = fileInfo.Name.Replace('_', ' ').Substring(0, fileInfo.Name.IndexOf('.'));

                            song.Location = fileInfo.FullName;
                            if (songName == null)
                                continue;
                            song.Name = songName;
                            songs.Add(song);
                        }
                    }
                }
                string[] directories = null;
                try
                {
                    directories = Directory.GetDirectories(path);
                }
                catch (UnauthorizedAccessException ex) { }
                if (directories != null)
                {
                    foreach (string directory in directories)
                    {
                        FindSongs(directory, ref songs);
                    }
                }
            }
        }