0
我通過單擊Button
將音頻文件添加到ListBox
。然後OpenFileDialog
(下面的代碼)的作品。我使用添加的文件ListBox
來播放(下面的代碼)。我點擊button_play
。有一個問題。當我點擊Button
進行分類時使用listBox1.Sorted = true
。排序後,應播放的音頻文件不會播放。在排序之前播放此音頻文件。也就是說,如果所有歌曲都有一個數字,那麼在排序後只會更改名稱,但數字並沒有改變。並且當您點擊button_play
時按數字播放。更改列表框中的選擇
private void button_add_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
label_load.Text = list_catalog.Items.Count.ToString();
}
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
foreach (String file in openFileDialog1.FileNames)
{
if (list_catalog.Items.Contains(Vars.GetFileName(file)))
{
}
else
{
Vars.Files.Add(file);
list_catalog.Items.Add(Vars.GetFileName(file));
hello.Visible = false;
}
}
}
private void button_play_Click(object sender, EventArgs e)
{
string current = Vars.Files[list_catalog.SelectedIndex];
Vars.CurrentTrackNumber = list_catalog.SelectedIndex;
BassLike.Play(current, BassLike.Volume);
label_time1.Text = TimeSpan.FromSeconds(BassLike.GetPosOfStream(BassLike.Stream)).ToString();
label_time2.Text = TimeSpan.FromSeconds(BassLike.GetTimeOfStream(BassLike.Stream)).ToString();
xrewind.Maximum = BassLike.GetTimeOfStream(BassLike.Stream);
xrewind.Value = BassLike.GetPosOfStream(BassLike.Stream);
timer1.Enabled = true;
}
您需要的文件名與索引列表項指標聯繫起來。有幾種方法,但我會創建一個包含路徑名和歌曲元數據的類作爲屬性,然後使用此類創建一個列表。排序時,您可以使用該類的任何屬性。 – imqqmi