Exemplo n.º 1
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog myFolder = new OpenFileDialog())
            {
                //Lets you select multiple files at once
                myFolder.Multiselect = true;

                myFolder.Filter           = "Mp3 File|*.mp3; | Wave File|*.wav| PlayList File|*.plst";
                myFolder.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);

                if (myFolder.ShowDialog() == DialogResult.OK)
                {
                    //Shows dialog box
                    _mp3Player = new Mp3Player(myFolder.FileName);
                }

                foreach (string file in myFolder.FileNames)
                {
                    //Displays file name without .mp3 & .wav extension
                    string fileInfo = Path.GetFileNameWithoutExtension(file);

                    listView1.Items.Add(fileInfo);
                    songs.Add(file);



                    //Enable buttons once listView is populated
                    btnPlay.Enabled    = true;
                    button1.Enabled    = true;
                    btnStop.Enabled    = true;
                    prevButton.Enabled = true;
                    nextButton.Enabled = true;
                }
            }
        }
Exemplo n.º 2
0
        private void openPlaylistToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LoadPlayList();
            using (OpenFileDialog myFolder = new OpenFileDialog())
            {
                if (myFolder.ShowDialog() == DialogResult.OK)
                {
                    _mp3Player        = new Mp3Player(myFolder.FileName);
                    _mp3Player.Repeat = false;

                    myFolder.Filter = "Playlist File|*.plst";
                    //OPENS A FILE AND READS IT
                    StreamReader infile = new StreamReader(myFolder.FileName);

                    while (!infile.EndOfStream)
                    {
                        var file = infile.ReadLine();

                        //Variable to hold songname after split
                        var songName = file.Split('\\');
                        //Variable to hold full length of string subtracted by 1 since all arrays start at 0;
                        int x = songName.Length - 1;

                        //Write each song to listbox and song list.
                        listView1.Items.Add(songName[x]);
                        songs.Add(file);
                    }

                    //CLOSE THE FILE
                    infile.Close();
                }
            }
        }