Exemplo n.º 1
0
        /// <summary>
        /// Event handler for when the file is dropped into the playlist area.
        /// It checks if the files are mp3s if they are we add them to the play list.
        /// </summary>
        /// <param name="sender">Not used</param>
        /// <param name="e">Used to get the file name</param>
        private void playList_Drop(object sender, System.Windows.DragEventArgs e)
        {
            Array a = (Array)e.Data.GetData(System.Windows.Forms.DataFormats.FileDrop);

            if (a != null)
            {
                for (int i = 0; i < a.Length; i++)
                {
                    string s = a.GetValue(i).ToString();
                    if (System.IO.Path.GetExtension(s) == ".mp3")
                    {
                        FileInfo temp = new FileInfo(s);

                        files.Add(new System.IO.FileInfo(s));
                    }
                }
                listView.Items.Clear();
                foreach (System.IO.FileInfo f in files)
                {
                    System.Windows.Controls.ListViewItem fileItem = new System.Windows.Controls.ListViewItem();
                    SongItem item = new SongItem(f.DirectoryName + "\\", f.Name);
                    listView.Items.Add(item);
                }
            }

            listViewLabel.Visibility = Visibility.Hidden;
        }
Exemplo n.º 2
0
        private void onTrackBack(object sender, MouseButtonEventArgs e)
        {
            selectedItem            = this.listView.ItemContainerGenerator.ContainerFromIndex(CurrentIndex) as System.Windows.Controls.ListViewItem;
            selectedItem.IsSelected = false;
            SongItem path = (SongItem)listView.Items[--CurrentIndex];

            playSong(path.directory + path.fileName);
            selectedItem            = this.listView.ItemContainerGenerator.ContainerFromIndex(CurrentIndex) as System.Windows.Controls.ListViewItem;
            selectedItem.IsSelected = true;
        }
Exemplo n.º 3
0
        /// <summary>
        /// This event handler activates when the list view is clicked and starts playing
        /// the song that was clicked.
        /// </summary>
        /// <param name="sender">Not used</param>
        /// <param name="e">Not used</param>
        private void listviewOnClick(object sender, MouseButtonEventArgs e)
        {
            CurrentIndex = listView.SelectedIndex;
            SongItem item = (SongItem)listView.SelectedItems[0];

            if (item != null)
            {
                playSong(item.directory + item.fileName);
            }
        }
Exemplo n.º 4
0
        private void OpenPlaylist(object sender, RoutedEventArgs e)
        {
            FolderBrowserDialog fbd    = new FolderBrowserDialog();
            DialogResult        result = fbd.ShowDialog();

            if (result != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            try
            {
                listView.Items.Clear();
                folderPath = fbd.SelectedPath + "\\";
                System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo(folderPath);
                files = new List <FileInfo>(directory.GetFiles("*.mp3"));

                foreach (System.IO.FileInfo f in files)
                {
                    SongItem item = new SongItem(folderPath, f.Name);
                    listView.Items.Add(item);
                }

                CurrentIndex = 0;
                if (listView.Items[CurrentIndex] != null)
                {
                    this.playSong(folderPath + listView.Items[CurrentIndex]);
                }

                listViewLabel.Visibility = Visibility.Hidden;


                /*
                 * selectedItem = this.listView.ItemContainerGenerator.ContainerFromIndex(0) as System.Windows.Controls.ListViewItem;
                 * selectedItem.IsSelected = true;*/
                //var test = listView.Items[0];
                //test.IsSelected = true;
            }
            catch (IOException)
            {
                System.Windows.MessageBox.Show("Cannot open file");
            }

            openPlaylist = true;
            trackForwardBtn.IsEnabled  = true;
            trackBackwardBtn.IsEnabled = true;
            playlistButton_Click(null, null);
        }