2017-03-06 4 views
0

Ich erstelle einen MP3-Player mit WMP-Bibliothek. Ich möchte mehrere Dateien zum Listenfeld hinzufügen, in dem sich meine Songs befinden. Aber unglücklicherweise füge ich nur ein Lied hinzu, obwohl ich mehr als eins ausgewählt habe. Ich kann meinen Fehler nicht finden.WMP-Bibliothek mehrere Dateien zum Listenfeld hinzugefügt

 openfile.FileName = String.Empty; 
     openfile.InitialDirectory = "D:\\"; 
     openfile.Filter = "MP3 Files(*.mp3)|*.mp3"; 
     openfile.RestoreDirectory = true; 
     openfile.Multiselect = true; 

     if (openfile.ShowDialog() == DialogResult.OK) 
     { 
      pictureBoxEqualizer.Visible = true; 
      listBoxSongs.Items.Clear(); 
      if (MediaPlayer.currentPlaylist.name != "myplaylist") 
      { 
       WMPLib.IWMPPlaylist songs = MediaPlayer.playlistCollection.newPlaylist("myplaylist"); 
       WMPLib.IWMPMedia media; 
       if (!playlist.Contains(openfile.SafeFileName)) 
       { 

         playpath.Add(openfile.FileName); 
         foreach (string file in playpath) 
         { 
          timer.Enabled = true; 
          media = MediaPlayer.newMedia(file); 
          songs.appendItem(media); 
         } 
         MediaPlayer.currentPlaylist = songs; 
         WMPLib.IWMPMedia current = MediaPlayer.currentPlaylist.get_Item(curr); 
         MediaPlayer.controls.playItem(current); 

         playlist.Add(MediaPlayer.currentMedia.getItemInfo("Artist") + " - " + MediaPlayer.currentMedia.name); 


        } 
        { 
         MessageBox.Show("Error!" + ex.Message, 
         "Error message!", MessageBoxButtons.OK, MessageBoxIcon.Error); 
        } 
       } 
       else 
       { 
        MessageBox.Show("The song is already in the list"); 
       } } 
      else 
      { 
       if (!playlist.Contains(openfile.SafeFileName)) 
       { 
         WMPLib.IWMPPlaylist songs = MediaPlayer.currentPlaylist; 
         WMPLib.IWMPMedia media; 
         playpath.Add(openfile.FileName); 
         media = MediaPlayer.newMedia(openfile.FileName); 
         songs.appendItem(media); 
         MediaPlayer.currentPlaylist = songs; 
         WMPLib.IWMPMedia current = MediaPlayer.currentPlaylist.get_Item(curr); 
         MediaPlayer.controls.playItem(current); 

         playlist.Add(MediaPlayer.currentMedia.getItemInfo("Artist") + " - " + MediaPlayer.currentMedia.name); 

        } 
        { 
         MessageBox.Show("Error!" + ex.Message, 
         "Error message!", MessageBoxButtons.OK, MessageBoxIcon.Error); 
        } 
       } 
       else 
       { 
        MessageBox.Show("The song is already in the list"); 
       } 
       listBoxSongs.Items.Clear(); 

       foreach (string item in playlist) 
       { 
        listBoxSongs.Items.Add(item); 
       } 
       } 
       listBoxSongs.SetSelected(curr, true); 
       curr++; 

     Title(); 

Antwort

0
  OpenFileDialog FileDialog = new OpenFileDialog(); 
      FileDialog.Multiselect = true; 
      if (FileDialog.ShowDialog() == DialogResult.OK) ; 
      { 
       fi = FileDialog.SafeFileNames; 
       pt = FileDialog.FileNames; 
       for (int i = 0; i < fi.Length; i++) 
       { 
        listBox1.Items.Add(fi[i]); 
       } 
      } 
Verwandte Themen