private void fileAdd_Click(object sender, EventArgs e) { List <CommonFileDialogFilter> cfdf = new List <CommonFileDialogFilter>(); cfdf.Add(new CommonFileDialogFilter("所有文件", "*.*")); cfdf.Add(new CommonFileDialogFilter("MP3", ".MP3")); cfdf.Add(new CommonFileDialogFilter("WAV", ".WAV")); cfdf.Add(new CommonFileDialogFilter("WMA", ".WMA")); cfdf.Add(new CommonFileDialogFilter("APE", ".APE")); cfdf.Add(new CommonFileDialogFilter("FLAC", ".FLAC")); cfdf.Add(new CommonFileDialogFilter("AAC", ".AAC")); cfdf.Add(new CommonFileDialogFilter("M4a", ".M4A")); cfdf.Add(new CommonFileDialogFilter("MP4", ".MP4")); cfdf.Add(new CommonFileDialogFilter("OGG", ".OGG")); List <string> files = FileOpenDialog.ShowDialog("Cup Player", false, cfdf); if (files != null) { XmlDocument xmlDoc = InitXml(); XmlNode root = xmlDoc.SelectSingleNode("SongList"); foreach (string file in files) { Song s = new Song(file, CommonProperty.getTitleFromPath(file)); ReadInfoFromFile(s); root.AppendChild(CreateElement(xmlDoc, s)); PlayController.Songs.Add(s); } xmlDoc.Save(XmlListPath); } }
private void playListBox_Drop(object sender, System.Windows.DragEventArgs e) { XmlDocument xmlDoc = InitXml(); XmlNode root = xmlDoc.SelectSingleNode("SongList"); if (e.Data.GetDataPresent(System.Windows.Forms.DataFormats.FileDrop)) { string[] FullName = ((string[])e.Data.GetData(System.Windows.Forms.DataFormats.FileDrop)); foreach (string t in FullName) { FileInfo fi = new FileInfo(t); if (CommonProperty.SupportFormat.Contains(fi.Extension.ToLower())) { Song song = PlayController.Songs.FirstOrDefault(s => s.FileUrl == fi.FullName); if (song == null) { song = new Song(fi.FullName, CommonProperty.getTitleFromPath(fi.FullName)); ReadInfoFromFile(song); root.AppendChild(CreateElement(xmlDoc, song)); PlayController.Songs.Add(song); } playListBox.ScrollIntoView(song); playListBox.SelectedValue = song; } else { Process.Start(fi.FullName); } } xmlDoc.Save(XmlListPath); } }
public void AddFileAndPlay(string path) { Song song = PlayController.Songs.FirstOrDefault(s => s.FileUrl.Replace(" ", "") == path); if (song == null) { XmlDocument xmlDoc = InitXml(); XmlNode root = xmlDoc.SelectSingleNode("SongList"); song = new Song(path, CommonProperty.getTitleFromPath(path)); ReadInfoFromFile(song); root.AppendChild(CreateElement(xmlDoc, song)); PlayController.Songs.Add(song); xmlDoc.Save(XmlListPath); } playListBox.ScrollIntoView(song); playListBox.SelectedValue = song; PlayController.PlayMusic(playListBox.SelectedIndex); }
void worker_DoWork(object sender, DoWorkEventArgs e) { FileInfo[] files = (FileInfo[])e.Argument; XmlDocument xmlDoc = InitXml(); XmlNode root = xmlDoc.SelectSingleNode("SongList"); int count = 0; foreach (FileInfo file in files) { if (CommonProperty.SupportFormat.Contains(file.Extension.ToLower())) { string fInfo = file.FullName; Song s = new Song(fInfo, CommonProperty.getTitleFromPath(fInfo)); ReadInfoFromFile(s); root.AppendChild(CreateElement(xmlDoc, s)); playListBox.Dispatcher.Invoke(new Action(() => PlayController.Songs.Add(s))); count++; } worker.ReportProgress(count * 100 / files.Count(), CommonProperty.getTitleFromPath(file.FullName)); System.Threading.Thread.Sleep(10); } xmlDoc.Save(XmlListPath); }