/// <summary> /// Returns playList builded from selected files. /// </summary> /// <param name="shufled"></param> /// <returns>PlayList</returns> public static PlayList BuildPlayListFromFiles(bool shufled) { PlayList list = null; OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "MP3 Files (.mp3)|*.mp3"; dialog.Multiselect = true; if (dialog.ShowDialog() == DialogResult.OK) { string[] path = dialog.FileNames; var fileInfos = path.Select(f => new FileInfo(f)); FileInfo[] fInfos = fileInfos.ToArray(); list = new PlayList(fInfos); if (list.getPlayListSize() == 0) { return(null); } if (shufled) { list.shufleQueue(); } } return(list); }
//-------------------------------menu items events handlers---------------------------- /// <summary> /// Event handler of Menu item "Open folder" /// Builds play List from user selected folder. Adds to play list all mp3 files in it. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void openFolderToolStripMenuItem_Click(object sender, EventArgs e) {// Checking if there is playing a song from previous playlist PlayList newPlayList = null; if (currentPlayList != null && currentPlayList.getCurentSong().playbackState() == "Playing") { newPlayList = Browser.BuildPlayList(random.Checked); if (newPlayList != null) { currentPlayList.getCurentSong().stop(); currentPlayList = newPlayList; } } else { newPlayList = Browser.BuildPlayList(random.Checked); } if (newPlayList != null) { //Adding to each song a Player event hendler which will listen for end file event to turn next file on play currentPlayList = newPlayList; for (int i = 0; i < currentPlayList.getPlayListSize(); i++) { currentPlayList.getElementAt(i).songFinished += PlayerInterface_songFinished; currentPlayList.getElementAt(i).firePlayBackChanged += PlayerInterface_firePlayBackChanged; } currentPlayList.getCurentSong().play(); // start play play.Image = VSAudioPlayer.Properties.Resources.pause_icon; //change icon initCombobox(); // Initialise combobox with playlist data. } }
/// <summary> /// Checks wether user already selected sufle option and builds playlist from folder selected. /// </summary> /// <param name="shufled"></param> /// <returns>PlayList</returns> public static PlayList BuildPlayList(bool shufled) { PlayList list = null; FolderBrowserDialog dialog = new FolderBrowserDialog(); if (dialog.ShowDialog() == DialogResult.OK) { string path = dialog.SelectedPath; DirectoryInfo dInfo = new DirectoryInfo(path); // File info docs FileInfo[] fInfor = dInfo.GetFiles("*.mp3"); list = new PlayList(fInfor); if (list.getPlayListSize() == 0) { return(null); } if (shufled) { list.shufleQueue(); } } return(list); }