Exemplo n.º 1
0
        private void LoadPlayList_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter           = "txt files (*.txt)|*.txt";
                openFileDialog.FilterIndex      = 1;
                openFileDialog.RestoreDirectory = true;

                if (openFileDialog.ShowDialog() == true)
                {
                    stopSong();
                    resetPlaylist();
                    var    converter = new NameConverter();
                    string Dir       = openFileDialog.FileName;

                    if (!File.Exists(Dir))
                    {
                        return;
                    }

                    var reader = new StreamReader(Dir);
                    _lastIndex = int.Parse(reader.ReadLine());
                    playlistListBox.SelectedIndex = _lastIndex;
                    SongDirectory.Clear();
                    _fullPaths.Clear();

                    while (true)
                    {
                        string result = reader.ReadLine();
                        if (result == null)
                        {
                            break;
                        }

                        SongDirectory.Add(result);
                        var info = new FileInfo(result);
                        _fullPaths.Add(info);
                    }
                }
            }
            catch (Exception error)
            {
                MessageBox.Show("Failed to load playlist!");
                resetPlaylist();
            }
        }
Exemplo n.º 2
0
        private void timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            Dispatcher.Invoke(() =>
            {
                if (_player.Source != null && _player.NaturalDuration.HasTimeSpan)
                {
                    var filename    = _fullPaths[_lastIndex].Name;
                    var converter   = new NameConverter();
                    var shortname   = converter.Convert(filename, null, null, null);
                    NameOfSong.Text = shortname.ToString();

                    TimeSlider.Maximum     = _player.NaturalDuration.TimeSpan.TotalSeconds;
                    TimeSlider.Value       = _player.Position.TotalSeconds;
                    currentPostTblock.Text = _player.Position.ToString(@"mm\:ss");
                    durationTblock.Text    = _player.NaturalDuration.TimeSpan.ToString(@"mm\:ss");
                }
            });
        }