1

I am new to C# and currently I am trying to make an audio player using BASS library. Right now I am creating the playlist using INI files like below:

[songs]
1=c:\lamfao.mp3
2=c:\test.mp3
[total_songs]
total=2

Everything is fine, but loading this type of INI file and showing it in ListView consumes a lot of time. Also there's no way to delete a song from this INI files. Hence, I am looking for help regarding loading and creating the playlists in C#. What I wanted to do is create a playlist with songs path and if possible with ID3 information like Album, Artist and Genre. Also like other media players, for example WinAMP or MediaMonkey, they take no time to display the playlist, how this can be achieved. I am trying to show the playlist in ListView with Type=Details. Is it possible to avoid the insertion of duplicate song in playlist?

Here's the current code which I am using to read INI files.

ListViewItem lvi;
ListViewItem.ListViewSubItem lvsi;
string name = "";
string album = "";
string artist = "";
string path = "";

if (File.Exists(CurrentPlaylistLocation))
{
this.progressBar1.Visible = true;
IniFile ini = new IniFile(CurrentPlaylistLocation); // INI Reading class in C# using Win32 API wrapper
string Total = ini.IniReadValue("Total_Files", "Total");
int items = Convert.ToInt32(Total);
this.progressBar1.Minimum = 0;
this.progressBar1.Maximum = items;
this.progressBar1.MarqueeAnimationSpeed = 100;
this.progressBar1.Style = ProgressBarStyle.Blocks;
int total = 0;
listView1.BeginUpdate();
for (int i = 1; i <= items; i++)
{
    path = ini.IniReadValue("songs", Convert.ToString(i));
    if(File.Exists(path))
    {
        // When user deletes a song from playlist, I add a .ignore in the last of song path
        // so, check if a song is deleted by user, if deleted then do not add it
        if (System.IO.Path.GetExtension(path).ToLower() != ".ignore")
        {
            PlayerEngine.GetTrackData(path, out name, out artist, out album); // Get META tag using Taglib sharp

            lvi = new ListViewItem();
            lvi.Text = name;

            lvsi = new ListViewItem.ListViewSubItem();
            lvsi.Text = album;
            lvi.SubItems.Add(lvsi);

            lvsi = new ListViewItem.ListViewSubItem();
            lvsi.Text = artist;
            lvi.SubItems.Add(lvsi);

            lvsi = new ListViewItem.ListViewSubItem();
            lvsi.Text = path;
            lvi.SubItems.Add(lvsi);

            this.listView1.BeginUpdate();
            this.listView1.Items.Add(lvi);
            this.listView1.EndUpdate();

            total++;
            this.progressBar1.Value = (i);
        }
    }
}
listView1.EndUpdate();
PlayerEngine.TotalTrackInTempPlaylist = listView1.Items.Count-1; // update the total number of songs loaded in player engine class
this.progressBar1.Visible = false;
MessageBox.Show("Playlist loading completed!");

Thanking you

Jim Carl
  • 41
  • 5
  • You are using WPF ? If so then use virtualization : http://msdn.microsoft.com/en-us/library/cc716879(v=vs.110).aspx – aybe Apr 27 '14 at 16:54
  • No I am using Winforms, .NET 4.0 Thank you – Jim Carl Apr 27 '14 at 17:16
  • I suggest you use a playlist format like m3u instead of the old ini format. This has nothing to do with your problems, though. Either way you will have to write some code. Reading/displaying text files cannot take any time at all. If it does, your code must be horribly wrong. You will have to show us the code, if you want us to point out any errors. – TaW Apr 27 '14 at 18:55
  • Ok, I have updated my question with the current code which I am using to read the INI file. It not takes so much time but yes it's around 10 to 15 seconds to load approx 1300 songs. – Jim Carl Apr 27 '14 at 21:06

0 Answers0