2017-03-06 6 views
0

wmpライブラリを使用してMP3プレーヤーを作成しています。私は私の歌があるリストボックスに複数のファイルを追加したい。しかし、不幸にも、私は複数の曲を選んでも1曲しか追加しません。私は間違いを見つけることができません。WMPライブラリリストボックスに複数のファイルが追加されました

 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(); 

答えて

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]); 
       } 
      } 
関連する問題