播放列表 我载入一个先保存好的mp3播放列表,但是播放不了。提示未将对象引用到实例,请各位提示下,我用的是c# 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //不好意思我用手机上网所以慢一点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; } 载入列表后,song=Null,问题应该在这里。请问大家应该怎样修改代码,谢谢了 Song是一个字符串数组,用来存放OpenFileDialog1.filename,我最上面就是代码,你可参考一下,就知道了 我看到了你的代码,如果Song只有这一个地方赋值的话,开始载入的时候,Song肯定是空的。 载入的时候,一面添加到ListBox中,同时也要保存到Song[]中。因为字符串数组本身是固定的,可以使用ArrayList或List <String>来代替普通数组。 load加载的页面怎样取到服务器控件 时间控制问题 如何实现一个集合类,类似ArrayList,但是又可以实现类试DataTable的绑定更新. 小弟求助,大侠留步 C#引用和C指针有什么区别? 怎么样根据hashtable的健值获取该健值的key 小小白求帮忙看下代码 能不能一次设置窗体各textbox,combotext的颜色 采集时,如何得出被采页面的创建时间 紧急求救:c#的,后台弹确认对话框实现页面转向,紧急求救!谢谢大家! GridView添加数据 关于Windows mobile 6.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;
}