-------------------- android培训、java培训、期待与您交流! ----------------------
我的思路是:
添加引用 windows media player
string path;
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofdg=new OpenFileDialog() ;
ofdg.Filter = "音频文件|*.mp3;*.wav;*.wma";
ofdg.Multiselect = true;
ofdg.CheckFileExists = true;
ofdg.CheckPathExists = true;
if (ofdg.ShowDialog() == DialogResult.OK
{
path = System.IO.Path.GetDirectoryName(ofdg.FileName);
foreach (string mufile in ofdg.SafeFileNames)
{
listBox1.Items.Add(mufile);
}
}
}
WMPLib.WindowsMediaPlayer wmp = new WMPLib.WindowsMediaPlayer();
private void listbox1_click(object sender, EventArgs e)
{
if (listBox1.SelectedItem != null)
{
wmp.URL =path +"\\"+ listBox1.Text ;
}
}
问题解决收获有:
1、 System.Media.soundplayer 类只能播放 .wav 文件。
2、openfiledialog 的属性 multiselect checkfileexists checkpathexists safename
3、foreach(类型 变量 in 集合)
4、获取openfiledialog的绝对路径 、文件名、 扩展名
System.IO.Path.GetFileName(ofdg.FileName));
System.IO.Path.GetDirectoryName(ofdg.FileName));
System.IO.Path.GetExtension(ofdg.FileName));
5、在listbox中添加文件列表方法不可取,windowsmediaplayer有 playlistCollection属性
---------------------- android培训、java培训、期待与您交流! ----------------------