public PlayListCollection()
 {
     try
     {
         playLists = new List <PlayList>();
         playLists.Add(new PlayList());
         currentPlayList = playLists[0];
         currentPlayItem = new PlayItem();
         currentPlayItem = currentPlayList.Items[0];
     }
     catch
     {
     }
 }
 public PlayListCollection(string path)
 {
     try
     {
         BinaryFormatter    bf  = new BinaryFormatter();
         PlayListCollection col = (PlayListCollection)bf.Deserialize(new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read));
         this.playLists       = col.playLists;
         this.currentPlayList = col.currentPlayList;
         this.currentPlayItem = col.currentPlayItem;
     }
     catch
     {
         playLists = new List <PlayList>();
         playLists.Add(new PlayList());
         currentPlayItem = new PlayItem();
         currentPlayList = playLists[0];
     }
 }
示例#3
0
        public void RandomTheList()
        {
            Random     rand  = new Random();
            List <int> array = new List <int>();

            for (int i = 0; i < Items.Count; i++)
            {
                int v = rand.Next(0, Items.Count - 1);

                if (array.Contains(v))
                {
                    while (!array.Contains(v))
                    {
                        v = rand.Next(0, Items.Count - 1);
                    }
                }

                array.Add(v);
                PlayItem item = Items[i];
                Items[i]            = Items[array.Last()];
                Items[array.Last()] = item;
            }
        }
        private void Add_Button_Click(object sender, MouseButtonEventArgs e)
        {
            window = App.Current.MainWindow as MainWindow;
            System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
            dlg.Filter      = "(*.mp3)|*.mp3";
            dlg.Multiselect = true;
            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                PlayItem[] item = new PlayItem[dlg.FileNames.Length];
                int        j    = 0;
                foreach (var i in dlg.FileNames)
                {
                    item[j] = new PlayItem(TagLib.File.Create(i));
                    j++;
                }
                window.collectionOfPlayLists.playLists.Where(p => p.Name == playListCurrent.Text).ElementAt(0).Items.AddRange(item);
                window.collectionOfPlayLists.currentPlayList = window.collectionOfPlayLists.playLists.Where(p => p.Name == playListCurrent.Text).ElementAt(0);
                window.collectionOfPlayLists.currentPlayItem = window.collectionOfPlayLists.currentPlayList.Items[0];

                playListView.Items.Clear();
                InitPlayListView(window.collectionOfPlayLists.playLists.Where(p => p.Name == playListCurrent.Text).ElementAt(0));
            }
        }
        public void InitPlayListView(PlayList playList)
        {
            if (playList.Items.Count != 0)
            {
                string             prevFolder = "";
                System.IO.FileInfo file       = new System.IO.FileInfo(playList.Items[0].Path);
                prevFolder = file.Directory.Name;
                for (int i = 0; i < playList.Items.Count; i++)
                {
                    if (i == 0 || prevFolder != new System.IO.FileInfo(playList.Items[i].Path).Directory.Name)
                    {
                        prevFolder = new System.IO.FileInfo(playList.Items[i].Path).Directory.Name;
                        ListViewItem itemHeader = new ListViewItem();
                        itemHeader.Height = 48;

                        Grid gridHeader = new Grid();
                        gridHeader.Height = 48;

                        Label labelNameOfFolder = new Label();
                        labelNameOfFolder.Name       = "NumberOfTrack";
                        labelNameOfFolder.Content    = prevFolder;
                        labelNameOfFolder.FontSize   = 19;
                        labelNameOfFolder.Foreground = new SolidColorBrush(Color.FromArgb(255, 191, 53, 23));
                        labelNameOfFolder.Margin     = new Thickness(0, 0, 486, 0);

                        gridHeader.Children.Add(labelNameOfFolder);
                        itemHeader.Content = gridHeader;
                        playListView.Items.Add(itemHeader);
                    }

                    ListViewItem item = new ListViewItem();
                    item.Height = 48;

                    Grid grid = new Grid();
                    grid.Height = 48;
                    grid.Margin = new Thickness(20, 0, 0, 0);

                    Label labelNumberOfTrack = new Label();
                    labelNumberOfTrack.Name       = "NumberOfTrack";
                    labelNumberOfTrack.Content    = i + 1 + ".";
                    labelNumberOfTrack.FontSize   = 13.5;
                    labelNumberOfTrack.Foreground = new SolidColorBrush(Color.FromRgb(128, 128, 128));
                    labelNumberOfTrack.Margin     = new Thickness(0, 0, 486, 0);

                    Label labelNameOfTrackAndComposer = new Label();
                    labelNameOfTrackAndComposer.Name       = "NameOfTrackAndComposer";
                    labelNameOfTrackAndComposer.Content    = playList.Items[i].Compositor + " - " + playList.Items[i].Name;
                    labelNameOfTrackAndComposer.FontSize   = 13.5;
                    labelNameOfTrackAndComposer.Foreground = new SolidColorBrush(Color.FromRgb(128, 128, 128));
                    labelNameOfTrackAndComposer.Margin     = new Thickness(29, 0, 271, 0);

                    Label labelDurationOfTrack = new Label();
                    labelDurationOfTrack.Name       = "DurationOfTrack";
                    labelDurationOfTrack.Content    = TimeSpan.FromSeconds(playList.Items[i].Seconds).ToString(@"mm\:ss");
                    labelDurationOfTrack.FontSize   = 13.5;
                    labelDurationOfTrack.Foreground = new SolidColorBrush(Color.FromRgb(128, 128, 128));
                    labelDurationOfTrack.Margin     = new Thickness(350, 0, 126, 0);

                    Label labelExtAndSize = new Label();
                    labelExtAndSize.Name       = "ExtAndSize";
                    labelExtAndSize.Content    = playList.Items[i].ShortToString();
                    labelExtAndSize.FontSize   = 11;
                    labelExtAndSize.Foreground = new SolidColorBrush(Color.FromRgb(169, 169, 169));
                    labelExtAndSize.Margin     = new Thickness(0, 23, 486, -23);

                    grid.Children.Add(labelNumberOfTrack);
                    grid.Children.Add(labelNameOfTrackAndComposer);
                    grid.Children.Add(labelDurationOfTrack);
                    grid.Children.Add(labelExtAndSize);

                    item.Content           = grid as object;
                    item.MouseDoubleClick += ListViewItem_MouseDown;

                    playListView.Items.Add(item);
                }
            }
            labelCountOfItemsPlayList.Content = playList.Items.Count;
            labelSumTimeOfPlayList.Content    = TimeSpan.FromSeconds(playList.TotalTimeInSeconds()).ToString("dd\\:hh\\:mm\\:ss");
            labelSizeOfItemsPlayList.Content  = PlayItem.BytesToString(playList.TotalSizeInBytes());
        }