Esempio n. 1
0
        private void btnAddMusic_Click(object sender, EventArgs e)
        {
            OpenFileDialog oFD = new OpenFileDialog()
            {
                Filter           = "Mp3 File|*.mp3",
                InitialDirectory = @"C:\Users\User\Desktop\Music\Playlist",
                Multiselect      = true,
            };

            if (oFD.ShowDialog() == DialogResult.OK)
            {
                foreach (String file in oFD.FileNames)
                {
                    Mp3Lib.Mp3File mFile = new Mp3Lib.Mp3File(file);
                    _mp3Player = new Mp3Player("0");
                    listitemsPath.Add(file);
                    listitemsName.Add(Path.GetFileName(file));
                    ListViewItem item = new ListViewItem(listitemsName[listitemsPath.Count - 1]);
                    string       artist = null, genre = null;

                    try
                    {
                        artist = mFile.TagHandler.Artist;
                        genre  = mFile.TagHandler.Genre;
                    }
                    catch (Exception)
                    {
                    }

                    if (artist != null)
                    {
                        listitemsArtist.Add(artist);
                    }
                    else
                    {
                        listitemsArtist.Add("Uncnown");
                    }
                    item.SubItems.Add(listitemsArtist[listitemsPath.Count - 1]);

                    if (genre != null)
                    {
                        listitemsGenre.Add(genre);
                        if (!comboBox2.Items.Contains(genre))
                        {
                            comboBox2.Items.Add(genre);
                        }
                    }
                    else
                    {
                        listitemsGenre.Add(" ");
                    }

                    item.SubItems.Add(listitemsGenre[listitemsPath.Count - 1]);

                    listView1.Items.Add(item);
                    if ((listitemsName.Count - 1) % 2 == 1)
                    {
                        listView1.Items[listitemsName.Count - 2].BackColor = Color.FromArgb(242, 242, 242);
                    }
                }
            }
        }
Esempio n. 2
0
        private void btnPlay_Click(object sender, EventArgs e)
        {
            _mp3Player.Dispose();
            Mp3Lib.Mp3File mFile;
            //player = new SoundPlayer();

            string dockName;

            if (listView1.SelectedIndices.Count > 0)
            {
                Mp3Player _mp3Player = new Mp3Player(listitemsPath[listView1.SelectedItems[0].Index]);
                mFile = new Mp3Lib.Mp3File(listitemsPath[listView1.SelectedItems[0].Index]);
                //player.SoundLocation = listitemsPath[listView1.SelectedItems[0].Index];
                dockName = Path.GetFileName(listitemsPath[listView1.SelectedItems[0].Index]);
            }
            else
            {
                Mp3Player _mp3Player = new Mp3Player(listitemsPath[listView1.Items[0].Index]);
                mFile = new Mp3Lib.Mp3File(listitemsPath[listView1.Items[0].Index]);
                //player.SoundLocation = listitemsPath[listView1.Items[0].Index];
                dockName = Path.GetFileName(listitemsPath[listView1.Items[0].Index]);
            }
            string dockTitle   = null;
            Image  dockPicture = null;

            try
            {
                if (dockName != null)
                {
                    lblBSName.Text = dockName;
                }

                dockTitle   = mFile.TagHandler.Artist;
                dockPicture = mFile.TagHandler.Picture;
            }
            catch (Exception)
            {
            }
            if (dockTitle != null)
            {
                label4.Text = dockTitle;
            }
            else
            {
                label4.Text = "Uncnown";
            }

            if (dockPicture != null)
            {
                pictureBox1.Image = new Bitmap(dockPicture);
            }
            else
            {
                pictureBox1.Image = Resource1.Def;
            }

            _mp3Player.SetVolume(trackBar1.Value);
            if (_mp3Player != null)
            {
                _mp3Player.Play();
            }
        }