private void Window_Loaded(object sender, RoutedEventArgs e) { //listview拖拽实现 this.dragMgr = new ListViewDragDropManager<Music>(this.musicList); if (File.Exists("默认.lst") == true) { StreamReader sr = new StreamReader("默认.lst"); string st = ""; while (sr.EndOfStream == false) { Music tmp = new Music(); st = sr.ReadLine(); tmp.musicPath = st; tmp.musicName = Music.GetMusicName(st); if ((tmp.musicPath != null) && (tmp.musicName != "?")) { music.Add(tmp); } } sr.Close(); //获取列表文件数目 count = music.Count; } //媒体打开时触发方法player_MediaOpened player.MediaOpened += new EventHandler(player_MediaOpened); //设置定时器同步播放进度 //获取或设置计时器刻度之间的时间段。 timer.Interval = TimeSpan.FromMilliseconds(500); timer.Tick += timer_Tick; timer.Start(); }
private void btOpen_Click(object sender, RoutedEventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "所有音频文件|*.mp3;*.wma;*.mid;*.asf;*.flac;*.wmv;*.wm;*.rm;*.mp4;*.mpg;*.mpeg;*.m1v;*.mp2;*.mpa;*.mpe;*.mpv2;*.m3u;*.wav;*.cda"; ofd.Multiselect = true; if (ofd.ShowDialog() == true) { foreach (string FileName in ofd.FileNames) { //创建一个临时音乐类用来写入音乐类集合music Music temp = new Music(); //创建一个对象用于处理出现关于字符串的问题 //去除FileName的目录路径,保留文件名及后缀 temp.musicPath = FileName; temp.musicName = Music.GetMusicName(FileName); //将temp写入集合 music.Add(temp); } } }