資源簡介
實現了播放器的絕大多數功能,例如:添加歌曲,保存列表,刪除歌曲,刪除重復,歌曲根據不同的關鍵字排序,播放模式的選擇,調節音量,進度,顯示歌曲進度時間和剩余時間,保存上次播放配置...。
代碼片段和文件信息
//?MusicList.cpp?:?implementation?file
//
#include?“stdafx.h“
#include?“MusicPalyer.h“
#include?“MusicList.h“
#ifdef?_DEBUG
#define?new?DEBUG_NEW
#undef?THIS_FILE
static?char?THIS_FILE[]?=?__FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
//?CMusicList
CMusicList::CMusicList()
{
}
CMusicList::~CMusicList()
{
//m_StringArray.RemoveAll();
m_vecArray.clear();
}
BEGIN_MESSAGE_MAP(CMusicList?CListBox)
//{{AFX_MSG_MAP(CMusicList)
ON_WM_RBUTTONDOWN()
//}}AFX_MSG_MAP
ON_COMMAND(IDM_OpenCurrentPath?OnMenuOpenCurrentPath)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//?CMusicList?message?handlers
//將歌曲添加到列表
void?CMusicList::AddToList(CString?strFilePath?int?nTimes?std::string?time?=?“?“)
{
MusicInfo?mTmp(strFilePath?nTimes?time);
m_vecArray.push_back(mTmp);
CString?strFileName?=?GetName(strFilePath);
AddString(Formattitle(strFileName));
}
//得到歌曲名
CString?CMusicList::GetName(CString?strFilePath)
{
CString?str;
int?nPos=-1;
int?nOldPos=-1;
while((nPos=strFilePath.Find(“\\“nPos+1))>0)
nOldPos=nPos;
str=strFilePath.Right(strFilePath.GetLength()-nOldPos-1);
strFilePath=str.Left(str.GetLength()-4);??
return?strFilePath;
}
//格式化歌曲名
CString?CMusicList::Formattitle(CString?strFileName)
{
CString?strTmp;
int?size?=?m_vecArray.size();
if?(size?>=?1?&&?size?<=?9)
strTmp.Format(“0%d??“?size);
else?if?(size?>=?10?&&?size?<=?99)
strTmp.Format(“%d??“?size);
else
strTmp.Format(“%d?“?size);
return?strTmp?+?strFileName;
}
//要播放的路徑
CString?CMusicList::GetMusicName(int?iIndex)
{
if?(iIndex?0)
iIndex?=?0;
return?m_vecArray.at(iIndex).strMusic;
}
//獲得歌曲數量
int?CMusicList::GetCount()
{
return?m_vecArray.size();
}
//上一曲、下一曲是否能用(多余了)
BOOL?CMusicList::IsEnable()
{
return?m_vecArray.size()?>?1???TRUE?:FALSE;
}
//初始化歌曲列表
void?CMusicList::InitFile()
{
m_strExePath?=?GetWorkPath();
CString?m_strLstPath;
m_strLstPath?=?m_strExePath?+?“\\000.lst“;
std::ifstream?ifile(m_strLstPath);
if?(!ifile)
return?;
std::string?strTmp;
CString?strTmpFilePath;
int?nTimes;
std::string?time;
int?select?=?0;
while?(std::getline(ifile?strTmp))
{
switch?(select)
{
case?0:
strTmpFilePath.Format(“%s“?strTmp.c_str());
select?=?1;
break;
case?1:
nTimes?=?atoi(strTmp.c_str());
select?=?2;
break;
case?2:
time?=?strTmp;
select?=?0;
break;
}
if?(select?==?0)
AddToList(strTmpFilePath?nTimes?time);
}
ifile.close();
}
//將歌曲路徑添加到文件
void?CMusicList::AddToFile(CString?str?int?nTimes?=?0)
{
SYSTEMTIME?st;
GetLocalTime(&st);
CString?strDate?strTime;
strDate.Format(“%4d-%2d-%2d“?st.wYear?st.wMonth?st.wDay);
strTime.Format(“?%2d-%2d-%2d“?st.wHour?st.wMinute?st.wSecond);
strTime?=?strDate?+?strTime;
std::string?time;
time?=?(LPCTSTR)strTime;
m_vecAr
- 上一篇:人臉跟蹤基于opencv
- 下一篇:c++ 計算m點問題
評論
共有 條評論