private void listView1_DoubleClick(object sender, EventArgs e) { isPaused = false; ListViewItem item = listView1.SelectedItems[0]; PlayListItem plItem = new PlayListItem(item.SubItems[0].Text, item.SubItems[2].Text, TimeSpan.Parse(item.SubItems[1].Text)); if (plItem == null) { return; } try { if (xWMP.Ctlcontrols.currentItem.sourceURL.Equals(item.SubItems[2].Text)) { xWMP.Ctlcontrols.stop(); xWMP.Ctlcontrols.play(); } else { IWMPPlaylist playlist = xWMP.playlistCollection.getByName(CurrentPlayList).Item(0); IWMPMedia media = xWMP.newMedia(item.SubItems[2].Text); while (!xWMP.Ctlcontrols.currentItem.sourceURL.Equals(item.SubItems[2].Text)) { xWMP.Ctlcontrols.next(); } xWMP.Ctlcontrols.play(); } adjustTimeBar(); tickAction(); myTimer.Start(); } catch (Exception) { MessageBox.Show("File not found! Delete song and add it from its new location!"); } }
//add song to current playlist private void addToolStripMenuItem_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(CurrentPlayList)) { MessageBox.Show("Select playlist first!"); } else { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Media Files|*.mpg;*.avi;*.wma;*.mov;" + "*.wav;*.mp2;*.mp3|All Files|*.*"; ofd.Multiselect = true; try { //List<PlayListItem> items = new List<PlayListItem>(); Dictionary <string, string> dsfsd = new Dictionary <string, string>(); if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { //string songName = Path.GetFileName(ofd.FileName); //path = ofd.FileName; //IWMPMedia media = xWMP.newMedia(path); //xWMP.URL = path; ////defaultPlaylist.appendItem(media); //PlayListItem item = PlayListManager.CreateItem(songName, path); //items.Add(item); //totalD = media.durationString; //if (totalD.Length < 6) //{ // totalD = "00:" + totalD; //} //TotalDuration += TimeSpan.Parse(totalD); //lbl_totalDuration.Text = TotalDuration.ToString(); //addItemToListView(songName, totalD, path); //dsfsd.Add(path, songName); //manager.AddSongsToPlayList(dsfsd, CurrentPlayList); List <PlayListItem> items = new List <PlayListItem>(); IWMPPlaylist playlist = xWMP.playlistCollection.getByName(CurrentPlayList).Item(0); foreach (string path in ofd.FileNames) { IWMPMedia media = xWMP.newMedia(path); //xWMP.URL = path; PlayListItem item = PlayListManager.CreateItem(Path.GetFileName(path), path); items.Add(item); playlist.appendItem(media); totalD = media.durationString; if (totalD.Length < 6) { totalD = "00:" + totalD; } TotalDuration += TimeSpan.Parse(totalD); lbl_totalDuration.Text = TotalDuration.ToString(); addItemToListView(Path.GetFileName(path), totalD, path); //dsfsd.Add(path, Path.GetFileName(path)); } Dictionary <string, string> nameUrlPair = items.ToDictionary(t => t.Path, t => t.Name); manager.AddSongsToPlayList(nameUrlPair, CurrentPlayList); LoadPlayList(CurrentPlayList); } } catch (ArgumentException ex) { MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void listView1_DoubleClick(object sender, EventArgs e) { isPaused = false; ListViewItem item = listView1.SelectedItems[0]; PlayListItem plItem = new PlayListItem(item.SubItems[0].Text, item.SubItems[2].Text, TimeSpan.Parse(item.SubItems[1].Text)); if (plItem == null) return; try { if (xWMP.Ctlcontrols.currentItem.sourceURL.Equals(item.SubItems[2].Text)) { xWMP.Ctlcontrols.stop(); xWMP.Ctlcontrols.play(); } else { IWMPPlaylist playlist = xWMP.playlistCollection.getByName(CurrentPlayList).Item(0); IWMPMedia media = xWMP.newMedia(item.SubItems[2].Text); while (!xWMP.Ctlcontrols.currentItem.sourceURL.Equals(item.SubItems[2].Text)) { xWMP.Ctlcontrols.next(); } xWMP.Ctlcontrols.play(); } adjustTimeBar(); tickAction(); myTimer.Start(); } catch (Exception) { MessageBox.Show("File not found! Delete song and add it from its new location!"); } }