public void DoAddFile(object sender, RoutedEventArgs args)
        {
            bool?result = OpenAudioFileDialog.ShowDialog();

            if (result ?? false)
            {
                foreach (string name in OpenAudioFileDialog.SafeFileNames)
                {
                    SongLibrary.SongList.Add(new Song()
                    {
                        Name = name, FilePath = name
                    });
                }
                UpdateLists();
            }
        }
Esempio n. 2
0
        public void DoAddFile(object sender, RoutedEventArgs args)
        {
            bool?result = OpenAudioFileDialog.ShowDialog();

            if (result ?? false)
            {
                foreach (string name in OpenAudioFileDialog.FileNames)
                {
                    try
                    {
                        var tagFile = TagLib.File.Create(name);
                        var tags    = tagFile.Tag;

                        SongLibrary.SongList.Add(new Song()
                        {
                            Name        = tags.Title == "" ? "Unknown Song" : tags.Title,
                            FilePath    = name,
                            Artist      = tags.FirstPerformer == "" ? "Unknown Artist" : tags.FirstPerformer,
                            AlbumName   = tags.Album == "" ? "Unknown Album" : tags.Album,
                            AlbumArtist = tags.FirstAlbumArtist,
                            Genre       = tags.FirstGenre,
                            TrackNumber = (int)tags.Track,
                            Year        = tags.Year == 0 ? "1970" : tags.Year + "",
                        });
                    } catch (Exception e)
                    {
                        SongLibrary.SongList.Add(new Song()
                        {
                            Name        = "Unknown Song",
                            FilePath    = name,
                            Artist      = "Unknown Artist",
                            AlbumName   = "Unknown Album",
                            AlbumArtist = "",
                            Genre       = "",
                            TrackNumber = 0,
                            Year        = "1970",
                        });
                    }
                }
                UpdateLists();
                AsyncSerialize(BackgroundCallback);
            }
        }