Example #1
0
        /// <summary>
        /// Selects an item inside the grid
        /// </summary>
        /// <param name="playlistItem"></param>
        public void SelectItem(PlaylistItem playlistItem)
        {
            int idxToSelect = PlaylistGrid.Items.IndexOf(playlistItem);

            if (idxToSelect >= 0)
            {
                PlaylistGrid.SelectedIndex = idxToSelect;
                PlaylistGrid.ScrollIntoView(PlaylistGrid.Items[idxToSelect]);
            }
        }
Example #2
0
        private void PlaylistButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Multiselect      = true;
            ofd.DefaultExt       = ".mp3";
            ofd.Filter           = "Audio files (*.mp3)|*.mp3";
            ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            if (ofd.ShowDialog() == true)
            {
                //Playlist.Clear();
                foreach (string filename in ofd.FileNames)
                {
                    var mp3File = TagLib.File.Create(filename);
                    Playlist.Add(new Track {
                        Media      = Player.newMedia(filename),
                        Title      = mp3File.Tag.Title,
                        Performers = mp3File.Tag.Performers,
                        Duration   = mp3File.Properties.Duration.ToString("mm\\:ss")
                    });
                    Console.WriteLine("Artist: " + String.Join(", ", mp3File.Tag.Performers));
                    Console.WriteLine("Track number: " + mp3File.Tag.Track);
                    Console.WriteLine("Title: " + mp3File.Tag.Title);
                    Console.WriteLine("Album: " + mp3File.Tag.Album);
                    Console.WriteLine("Year: " + mp3File.Tag.Year);
                    Console.WriteLine("Genre: " + mp3File.Tag.FirstGenre);
                    Console.WriteLine("Bitrate: " + mp3File.Properties.AudioBitrate + " kbps");
                    Console.WriteLine("Channels: " + mp3File.Properties.AudioChannels);
                    Console.WriteLine("Duration: " + mp3File.Properties.Duration.ToString("mm\\:ss"));
                    RowDefinition gridRow = new RowDefinition();
                    gridRow.Height = new GridLength(50);
                    Style st = FindResource("PlayerButton") as Style;
                    PlaylistGrid.RowDefinitions.Add(gridRow);
                    Button TrackPlayButton = new Button()
                    {
                        Name                = "PlayTrackButton" + (Playlist.Count - 1).ToString(),
                        Style               = st,
                        Foreground          = new SolidColorBrush(Color.FromRgb(255, 255, 255)),
                        Background          = Brushes.Transparent,
                        Height              = 40,
                        Width               = 40,
                        Cursor              = Cursors.Hand,
                        HorizontalAlignment = HorizontalAlignment.Left,
                        Margin              = new Thickness(10, 0, 10, 0),
                    };
                    TrackPlayButton.MouseEnter += TrackPlayButton_MouseEnter;
                    TrackPlayButton.MouseLeave += TrackPlayButton_MouseLeave;
                    TrackPlayButton.Click      += TrackPlayButton_Click;
                    PathGeometry pg = new PathGeometry();
                    pg.FillRule = FillRule.Nonzero;
                    PathFigureCollectionConverter pfcc = new PathFigureCollectionConverter();
                    pg.Figures = (PathFigureCollection)pfcc.ConvertFrom("M8 5v14l11-7z");
                    Path ButtonPath = new Path()
                    {
                        Name                = "PlayTrackButton" + (Playlist.Count - 1).ToString() + "Path",
                        Fill                = new SolidColorBrush(Color.FromRgb(255, 255, 255)),
                        Data                = pg,
                        Stretch             = Stretch.Fill,
                        Height              = 15,
                        Width               = 11,
                        HorizontalAlignment = HorizontalAlignment.Center,
                        VerticalAlignment   = VerticalAlignment.Center
                    };
                    Grid PathGrid = new Grid()
                    {
                        Width  = 10,
                        Height = 15,
                        HorizontalAlignment = HorizontalAlignment.Center,
                        VerticalAlignment   = VerticalAlignment.Center
                    };
                    Label TrackName = new Label()
                    {
                        Content           = String.Join(", ", mp3File.Tag.Performers) + " - " + mp3File.Tag.Title,
                        Foreground        = Brushes.White,
                        VerticalAlignment = VerticalAlignment.Center,
                        Margin            = new Thickness(60, 0, 0, 0),
                    };
                    PathGrid.Children.Add(ButtonPath);
                    TrackPlayButton.Content = PathGrid;
                    Border Container = new Border()
                    {
                        Height          = 50,
                        Background      = Brushes.Transparent,
                        BorderBrush     = new SolidColorBrush(Color.FromRgb(55, 70, 79)),
                        BorderThickness = new Thickness(0, 0, 0, 2),
                        Child           = TrackPlayButton
                    };

                    Grid.SetRow(Container, Playlist.Count - 1);
                    Grid.SetColumn(Container, 0);
                    Grid.SetRow(TrackName, Playlist.Count - 1);
                    Grid.SetColumn(TrackName, 0);
                    PlaylistGrid.Children.Add(Container);
                    PlaylistGrid.Children.Add(TrackName);
                    if (PlaylistGrid.FindName(ButtonPath.Name) == null)
                    {
                        PlaylistGrid.RegisterName(ButtonPath.Name, ButtonPath);
                    }
                    if (PlaylistScroll.Height < 250)
                    {
                        PlaylistScroll.Height += 50;
                    }
                }
            }
            Player.controls.stop();
            if (Playlist.Count > 0)
            {
                Player.currentMedia = Playlist[0].Media;
                CurrentMediaIndex   = 0;
                PlayerToggle();
            }
        }