0

Well, I'm making a simple winform to create a text file containing paths to various songs. It's just a simplistic playlist for a visualizer/audio player that I've been working on (using XNA, C#, and Bass.Net). I'd like to use TagLib access and display song titles, artists, and to sort playlists.

This is the code that I've been using:

    private void button1_Click(object sender, EventArgs e)
    {
        selectPlaylist.ShowDialog();
        string filePath = string.Empty;
        if (selectPlaylist.FileName.EndsWith(".txt"))
        {
            StreamReader fInput = new StreamReader(selectPlaylist.FileName);
            playlistName = fInput.ReadLine();
            playlistNameTextBox.Text = playlistName;
            while (!fInput.EndOfStream)
            {
                filePath = fInput.ReadLine();
                if (!filePath.Contains(":\\")) continue;                   
                songInfo.Add(TagLib.File.Create(filePath).Tag); //List<TagLib.Tag>
                songs.Add(filePath); //List<string>
            }
            songNamesComboBox.DataSource = songs;
            fInput.Close();
            fInput = null; //don't even know if I need this
        }
    }

Regardless of what files I use, all of the Tag properties/attributes are empty. I created a console application and did the same thing (creating a file and saving its Tag to a variable) and was able to correctly access tag information.

TagLib.Tag tag = TabLib.File.Create("D:\\Music\\Electronic Music\\" +
    "Instrumental Core\\The Angels Among Demons.mp3").Tag;
Console.WriteLine(tag.Title);

I'm a bit new to C#, but I cannot figure what I've done wrong. Why would the latter (console application) work, but not my winform?

Keswiik
  • 1
  • 1
  • You are using it correctly - or at least the same way I do. It might be an issue of permissions. Access to the root folder of the boot drive can be problematic. Try working from something like "C:\Temp" – Ňɏssa Pøngjǣrdenlarp Dec 21 '14 at 22:49
  • @Plutonix Well, I was just using that path as an example. Most of my files are organized on another drive (e.g. "D:\Music\Electronic Music\Instrumental Core\The Angels Among Demons.mp3"), so it's shouldn't be an issue with permissions. I've edited my post to avoid causing that kind of confusion again. Thank you for the answer, though! – Keswiik Dec 21 '14 at 23:33

0 Answers0