private void _timer_Tick(object sender, EventArgs e) { if (_player.Source != null) { var filename = _fullPaths[_lastIndex].Name; var converter = new NameConverter(); var shortname = converter.Convert(filename, null, null, null); var currentPos = _player.Position.ToString(@"mm\:ss"); var duration = items[_lastIndex].Timeduration; Time.Text = String.Format($"{currentPos} - {duration} "); NameSong.Text = shortname.ToString(); } }
private void Add_Button_Click(object sender, RoutedEventArgs e) { if (_inPlaylist) // neu playlist ton tai thi moi duoc add vao { var screen = new Microsoft.Win32.OpenFileDialog(); screen.Filter = "Mp3 (*.MP3)|*.MP3|" + "All file (*.*)|*.*"; screen.Multiselect = true; // cho phep chon nhieu bai if (screen.ShowDialog() == true) { foreach (var item in screen.FileNames) { var info = new FileInfo(item); _fullPaths.Add(info); Mp3FileReader reader = new Mp3FileReader(info.FullName); TimeSpan duration1 = reader.TotalTime; var time = duration1.TotalSeconds; var filename = _fullPaths[_fullPaths.Count - 1].Name; var converter = new NameConverter(); var shortname = converter.Convert(filename, null, null, null).ToString(); var duration = TimeSpan.FromSeconds(time).ToString(@"mm\:ss"); //Debug.WriteLine($"{shortname}"); var itemBinding = new itemList(); itemBinding.Name = shortname; itemBinding.Index = _fullPaths.Count - 1; itemBinding.Timeduration = duration; items.Add(itemBinding); Indexes.Add(_fullPaths.Count - 1); } } _isPlaying = false; PlayIcon.Kind = MaterialDesignThemes.Wpf.PackIconKind.Play; } else { System.Windows.MessageBox.Show("Please Create playlist to add file..."); } }
private void Load_button_Click(object sender, RoutedEventArgs e) { var screen = new Microsoft.Win32.OpenFileDialog(); screen.Filter = "Text files (*.TXT)|*.TXT|" + "All file (*.*)|*.*"; if (screen.ShowDialog() == true) { var filename_playlist = screen.FileName; var temp = new FileInfo(filename_playlist); var reader = new StreamReader(filename_playlist); var firstLine = reader.ReadLine(); // luu tong so bai hat co trong playlist if (firstLine == null) { System.Windows.MessageBox.Show("File error! Can't load playlist. Please choose another file.."); } else { if (items.Count > 0) { _player.Pause(); _timer.Stop(); } int count = int.Parse(firstLine); // so luong var FileNameplaylist = temp.Name; var secondLine = reader.ReadLine(); // luu bai hat phat cuoi cung truoc khi save - khong su dung var token = FileNameplaylist.Split(new string[] { "." }, StringSplitOptions.None); name_playlist.Text = token[0]; _fullPaths = new List <FileInfo>(); items = new BindingList <itemList>(); Indexes = new List <int>(); _lastIndex = -1; _isPlaying = false; PlayIcon.Kind = MaterialDesignThemes.Wpf.PackIconKind.Play; _isShuffle = false; _inPlaylist = true; // == 1:lap vo tan ; == 0: lap 1 lans _modeReplay = -1; for (int i = 0; i < count; i++) { var info = new FileInfo(reader.ReadLine()); _fullPaths.Add(info); Mp3FileReader reader1 = new Mp3FileReader(info.FullName); TimeSpan duration1 = reader1.TotalTime; var time = duration1.TotalSeconds; var filename = _fullPaths[_fullPaths.Count - 1].Name; var converter = new NameConverter(); var shortname = converter.Convert(filename, null, null, null).ToString(); var duration = TimeSpan.FromSeconds(time).ToString(@"mm\:ss"); //Debug.WriteLine($"{shortname}"); var itemBinding = new itemList(); itemBinding.Name = shortname; itemBinding.Index = _fullPaths.Count - 1; itemBinding.Timeduration = duration; items.Add(itemBinding); Indexes.Add(_fullPaths.Count - 1); // } listmusic_playlist.ItemsSource = items; } System.Windows.MessageBox.Show("Load thanh cong"); } else { // Khong load file } }
private void Window_Loaded(object sender, RoutedEventArgs e) { string load_playlist = isLastPlayList(); if (load_playlist == "") { System.Windows.MessageBox.Show("Khong co playlist de load"); } else { var reader = new StreamReader(load_playlist); var firstLine = reader.ReadLine(); // luu tong so bai hat co trong playlist if (firstLine == null) { System.Windows.MessageBox.Show("File error! Can't load playlist. Please choose another file.."); } else { int count = int.Parse(firstLine); // so luong var secondLine = reader.ReadLine(); // luu bai hat phat cuoi cung truoc khi save - khong su dung var token = load_playlist.Split(new string[] { "." }, StringSplitOptions.None); // tach .txt name_playlist.Text = token[0]; var curSong = new FileInfo(secondLine); var nameSong = curSong.Name; var converter1 = new NameConverter(); var shortnameSong = converter1.Convert(nameSong, null, null, null).ToString(); NameSong.Text = shortnameSong; _fullPaths = new List <FileInfo>(); items = new BindingList <itemList>(); Indexes = new List <int>(); _lastIndex = -1; _isPlaying = false; _isShuffle = false; _inPlaylist = true; //== 1:lap vo tan ; == 0: lap 1 lans _modeReplay = -1; for (int i = 0; i < count; i++) { var info = new FileInfo(reader.ReadLine()); _fullPaths.Add(info); var filename = _fullPaths[_fullPaths.Count - 1].Name; if (filename == curSong.Name) // tim index { _lastIndex = i; // cap nhat lastIndex // MessageBox.Show($"{_lastIndex}"); } var converter = new NameConverter(); var shortname = converter.Convert(filename, null, null, null).ToString(); Mp3FileReader reader_mp3 = new Mp3FileReader(info.FullName); TimeSpan duration1 = reader_mp3.TotalTime; var time = duration1.TotalSeconds; var duration = TimeSpan.FromSeconds(time).ToString(@"mm\:ss"); //Debug.WriteLine($"{shortname}"); var itemBinding = new itemList(); itemBinding.Name = shortname; itemBinding.Index = _fullPaths.Count - 1; itemBinding.Timeduration = duration; items.Add(itemBinding); Indexes.Add(_fullPaths.Count - 1); } listmusic_playlist.ItemsSource = items; _isLoaded = true; System.Windows.MessageBox.Show("Load successfully.."); } } }