我载入一个先保存好的mp3播放列表,但是播放不了。提示未将对象引用到实例,请各位提示下,我用的是c#

解决方案 »

  1.   

    //不好意思我用手机上网所以慢一点
    FileStream file_1 = null;
                    try
                    {
                        file_1 = File.Open( @"C:\m_name.m3u", FileMode.Create);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("±£´æÁбíʧ°Ü");
                    }                StreamWriter writer = new StreamWriter(file_1);
                    for (int i = 0; i < this.listBox1.Items.Count; i++)
                    {
                        writer.WriteLine(this.listBox1.Items[i].ToString());
                    }
                    writer.Close();//上面是保存列表;
    //下面是载入列表;;
    string strLine;
                try
                {
                    FileStream afile = new FileStream(@"C:\m_name.m3u", FileMode.Open);
                    StreamReader sw = new StreamReader(afile);
                    strLine = sw.ReadLine();
                    while (strLine != null)
                    {
                        listBox1.Items.Add(strLine);
                        strLine = sw.ReadLine();                }
                    sw.Close();
                }
                catch (IOException ex)
                {
                    Console.WriteLine("sorry");
                    Console.WriteLine(ex.ToString());
                    return;
                }
    //下面是调用播放;
     private void player()
                {
                   
                   mp3player.URL =Song[SongID ]; 
                   
                   mp3player.settings.autoStart = true;
                    mp3player.settings.volume =100;
                    timer1.Enabled = true;
                  
                }
    //如果不要保存和载入列表,单独打开文件可播放
    if (openFileDialog1.FileName !=null & openFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                       Song[SongNum] = openFileDialog1.FileName;
                      string MyShortFileName = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf('\\') + 1);                  listBox1.Items.Add(openFileDialog1.FileName/*MyShortFileName.ToLower().Replace(".mp3", "")*/);
                        SongNum++;
                        mp3total++;
                        listBox1.SelectedIndex = 0;
                    }
      

  2.   

    载入列表后,song=Null,问题应该在这里。请问大家应该怎样修改代码,谢谢了
      

  3.   

    Song是一个字符串数组,用来存放OpenFileDialog1.filename,我最上面就是代码,你可参考一下,就知道了
      

  4.   

    我看到了你的代码,如果Song只有这一个地方赋值的话,开始载入的时候,Song肯定是空的。
      

  5.   

    载入的时候,一面添加到ListBox中,同时也要保存到Song[]中。因为字符串数组本身是固定的,可以使用ArrayList或List <String>来代替普通数组。