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