16,548
社区成员




TRY
{
CStdioFile f(csPath,
CFile::modeRead |
CFile::typeText |
CFile::shareExclusive);//这个是关于读取文件的函数
// 读文件头"#EXTM3U"
if (!f.ReadString(csLine))//这个是读取头文件 为什么要读取这个头文件啊
{
return 0;
}
if (!(csLine == _T("#EXTM3U")))
{
AfxMessageBox(_T("文件格式错误!\n") + csPath);
return 0;
}
while (f.ReadString(csLine)) // 按行读取
{
csHead=csLine.Left(7);
csHead.MakeUpper();
if (csHead == _T("#EXTINF"))从下面开始就不是很明白其中的细节作用了 谢谢注释下
{
csInfo = csLine;
if ((nColon=csInfo.Find(':'))!=-1 &&
(nComma=csInfo.Find(','))!=-1)
{
csLength = csInfo.Mid(nColon + 1, nComma - nColon);
csTitle = csInfo.Mid(nComma + 1);
csLength.Format("%d:%02d", nLength/60, nLength%60);
}
continue;
}
else
{
csPath = csLine;
if (m_listctrlSongList.GetItemCount() != 0 && nCount == 0)
{
m_listctrlSongList.DeleteAllItems(); // 清空歌曲列表
}
if (csTitle.IsEmpty()) // 标题为空
{
GetFileTitle(csPath.GetBuffer(255),
csTitle.GetBuffer(255),
255);
csTitle = (char)(nCount+1+48) + csTitle;
AfxMessageBox(csTitle);
}
if (csLength.IsEmpty()) // 长度为空
csLength = _T("00:00");
m_listctrlSongList.InsertItem(nCount, csTitle);
m_listctrlSongList.SetItemText(nCount, 1, csLength);
m_listctrlSongList.SetItemText(nCount, 2, csPath);
UpdateSongInfo(nCount); // 更新歌曲信息
nCount++;
csInfo=_T("");
csPath=_T("");
csLength=_T("");
csTitle=_T("");
}