我是C#的新手,目前我正在尝试使用BASS库制作音频播放器。现在我正在使用如下的INI文件创建播放列表:
[songs]
1=c:\lamfao.mp3
2=c:\test.mp3
[total_songs]
total=2
一切都很好,但加载这种类型的INI文件并在ListView中显示它会耗费大量时间。此外,还无法从此INI文件中删除歌曲。因此,我正在寻找有关在C#中加载和创建播放列表的帮助。我想要做的是创建一个带有歌曲路径的播放列表,如果可能的话还可以创建像Album,Artist和Genre这样的ID3信息。 与其他媒体播放器一样,例如WinAMP或MediaMonkey,他们会花时间显示播放列表,如何实现这一点。我试图在ListView中显示Type = Details的播放列表。 是否可以避免在播放列表中插入重复的歌曲?
这是我用来读取INI文件的当前代码。
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!");
感谢你