//-------------------------------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> /// Event hendler, ocured when play back data is changed, every 50ms state checked in Mp3 class. /// </summary> void PlayerInterface_firePlayBackChanged() { this.Invoke((MethodInvoker) delegate { //trackBar1.Value = (int)(trackBar1.Maximum * currentPlayList.getCurentSong().Position / currentPlayList.getCurentSong().TotalLenght);// runs on UI thread trackBar1.Value = (int)(trackBar1.Maximum * currentPlayList.getElementAt(currentPlayList.Index).Position / currentPlayList.getElementAt(currentPlayList.Index).TotalLenght); }); this.showPanel.Invalidate();// Caled to redraw showPanel with new info. }