private void BackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            //On app start CurrentPlaying object is null so we must check for it before going further
            if (_currentPlaying == null)
            {
                return;
            }
            var index = Mp3Files.IndexOf(_currentPlaying);

            if (_player.playState == WMPPlayState.wmppsStopped)
            {
                if (index < Mp3Files.Count - 1)
                {
                    Play(Mp3Files[index + 1]);                     //play next song when there is any and player stopped which happens only on media end, but because we can miss media end state we use this, which works fine
                }
                else
                {
                    Play(Mp3Files[0]);
                }
            }
            //Progress bar and time progress updating
            var timeSpan = TimeSpan.FromSeconds(_player.controls.currentPosition);

            CurrentPositionTextBlock.Text = String.Format("{0}:{1:00}", timeSpan.Minutes, timeSpan.Seconds);
            ProgressBar.Value             = _player.controls.currentPosition / _currentPlaying.MaxPosition * 100;
        }
示例#2
0
        private void Mp3Files_OnKeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.A)
            {
                if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
                {
                    Mp3Files.SelectedItems.Clear();
                    Mp3Files.SelectAll();
                }
            }

            if (e.Key == Key.Escape)
            {
                Mp3Files.SelectedItems.Clear();
            }
        }
        private void PreviousButton_OnClick(object sender, RoutedEventArgs e)
        {
            if (_currentPlaying == null)
            {
                return;
            }
            var index = Mp3Files.IndexOf(_currentPlaying);

            if (index > 0)
            {
                Play(Mp3Files[index - 1]);
            }
            else
            {
                Play(Mp3Files[Mp3Files.Count - 1]);
            }
        }
        private void NextButton_OnClick(object sender, RoutedEventArgs e)
        {
            if (_currentPlaying == null)
            {
                return;
            }
            var index = Mp3Files.IndexOf(_currentPlaying);

            if (index < Mp3Files.Count - 1)
            {
                Play(Mp3Files[index + 1]);
            }
            else
            {
                Play(Mp3Files[0]);
            }
        }
        private void OpenDirectory_OnClick(object sender, RoutedEventArgs e)
        {
            CommonOpenFileDialog dialog = new CommonOpenFileDialog();

            dialog.InitialDirectory = "C:\\Users";
            dialog.IsFolderPicker   = true;
            if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
            {
                var     files    = Directory.GetFiles(dialog.FileName, "*.mp3");
                Mp3File firstMp3 = new Mp3File(files[0]);
                Mp3Files.Add(firstMp3);
                for (int i = 1; i < files.Length; i++)
                {
                    Mp3Files.Add(new Mp3File(files[i]));
                }
                Play(firstMp3);
            }
        }
        private void OpenButton_OnClick(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog
            {
                Multiselect = true,
                Filter      = "mp3 files (*.mp3)|*.mp3"
            };

            openFileDialog.ShowDialog();


            if (openFileDialog.FileNames.Length > 0)
            {
                Mp3File firstMp3 = new Mp3File(openFileDialog.FileNames[0]);
                Mp3Files.Add(firstMp3);
                for (int i = 1; i < openFileDialog.FileNames.Length; i++)
                {
                    Mp3Files.Add(new Mp3File(openFileDialog.FileNames[i]));
                }
                Play(firstMp3);
            }
        }
        private void DeleteMp3File_Click(object sender, RoutedEventArgs e)
        {
            if (GetCurrentSelectedIndex() < 0)
            {
                return;
            }

            var result = MessageBox.Show($"Вы действительно " +
                                         $"хотите удалить файл {GetCurrentSelectedFilename()}",
                                         "Удаление файла", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (result == MessageBoxResult.Yes)
            {
                string fileAbsolutePath = basePath + GetCurrentSelectedFilename();
                int    selectedIndex    = GetCurrentSelectedIndex();
                Task.Run(() => {
                    File.Delete(fileAbsolutePath);
                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        Mp3Files.RemoveAt(selectedIndex);
                    }));
                });
            }
        }
示例#8
0
        private void LoadFiles(string folderpath)
        {
            List <TagTypes> tags = new List <TagTypes>()
            {
                TagTypes.Ape, TagTypes.Apple, TagTypes.Asf, TagTypes.AudibleMetadata, TagTypes.DivX,
                TagTypes.FlacMetadata, TagTypes.GifComment, TagTypes.IPTCIIM, TagTypes.Id3v1, TagTypes.Id3v2,
                TagTypes.JpegComment, TagTypes.MovieId, TagTypes.Png, TagTypes.RiffInfo, TagTypes.TiffIFD,
                TagTypes.XMP, TagTypes.Xiph
            };

            List <string> additionalTags = new List <string>()
            {
                "album", "artists", "comment", "lyrics", "composers", "disc",
                "disccount", "genres", "performers", "title", "trackcount",
                "year"
            };

            Mp3Files.SelectionMode = SelectionMode.Multiple;
            Mp3Files.Items.Clear();
            var files = GetFilesInFolder(folderpath);

            foreach (var file in files)
            {
                using (TagLib.File f = TagLib.File.Create(file))
                {
                    string name = Path.GetFileName(file);

                    Trace.WriteLine("Some info: " + name);
                    foreach (var tag in tags)
                    {
                        try
                        {
                            var info = f.GetTag(tag);
                            if (info != null)
                            {
                                Trace.WriteLine("  " + tag + ": " + info);
                            }
                        }
                        catch
                        {
                            // ignore
                        }
                    }

                    foreach (var tagname in additionalTags)
                    {
                        try
                        {
                            ShowTag(f, tagname);
                        }
                        catch
                        {
                            // ignore
                        }
                    }

                    //string tagPerfomer = string.Join(",", f.Tag.PerformersSort);
                    string tagAlbum = f.Tag.Album;
                    string tagTitle = f.Tag.Title;

                    bool hasId3Tag = !string.IsNullOrEmpty(tagAlbum) || !string.IsNullOrEmpty(tagTitle);

                    string additionalInformation = string.Format("{0} - {1}",
                                                                 string.IsNullOrEmpty(tagAlbum) ? "x" : tagAlbum,
                                                                 string.IsNullOrEmpty(tagTitle) ? "x" : tagTitle
                                                                 );

                    var item = new FileItem()
                    {
                        Name      = string.Format("{0} ({1})", name, additionalInformation),
                        Filename  = file,
                        HasId3Tag = hasId3Tag
                    };

                    Mp3Files.Items.Add(item);
                }
            }
            Mp3Files.SelectAll();
        }