关于播放器的打开的问题 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("");
}
{
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("");
}
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 = csLine; 把读取的字符串赋给csInfo
if ((nColon=csInfo.Find(':'))!=-1 &&//找到:的位置返回位置值给nColon
(nComma=csInfo.Find(','))!=-1)//找到,把“,”在字符串中的位置赋给nComma
{
csLength = csInfo.Mid(nColon + 1, nComma - nColon);//Mid是提取从nColon+1开始到nComma-nColon之间的字符串。既歌曲长度然后赋给csLnegth
csTitle = csInfo.Mid(nComma + 1);//从csInfo中提取nComma+1到完的字符串,既:歌曲的名字
csLength.Format("%d:%02d", nLength/60, nLength%60);//将保存长度的字符串转化为十进制的格式
}
continue;//完了之后跳出此次循环继续下一次循环。
}
else//读取在保存的cspath路径
{
csPath = csLine;//将路径的名字赋给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++;希望对大家有用