📄 playmp3dlg.cpp
字号:
m_ListMp3.SetCurSel(xxx);
// m_ListMp3.GetText(xxx,name_);
name_ = openfile_dlg.array_str.GetAt(xxx);
// mSourceFile.Format( strPath + L"mp3\\%s",name_);
mSourceFile = name_;
///////////////
lrc.Free();
CString strMP3NAME,strLRCNAME;
strMP3NAME = mSourceFile.Left(mSourceFile.GetLength() - 4);
strLRCNAME = strMP3NAME + ".lrc";
str_lrc = L"";
if ((lrc.Open(strLRCNAME)))
{
b_yesLrc = true;
}
else
{
// m_lrc.ShowWindow(SW_HIDE);
}
GetMp3INFO(mSourceFile);
b_mp3info = true;
mp3CreateGraph();
InvalidateRect(CRect(19,182,155 + 19,182+11),false);
mp3PLAY();
b_play_or_pause = true;
return;
}
newPos = int(pos * 101 / duration);
m_StateDian.MoveWindow(newPos + 151 ,201,29,20);
}
CDialog::OnTimer(nIDEvent);
}
void CPLAYMP3Dlg::GetVolume()
{
DWORD dwVolume;
DWORD sVolume;
DWORD dwType ;
dwType = REG_DWORD ;
waveOutGetVolume(0, &dwVolume);
sVolume=dwVolume>>16;
if(sVolume==0)
out=0;
else if(sVolume<((DWORD)0xffff/9*1))
out=1;
else if(sVolume<((DWORD)0xffff/9*2))
out=2;
else if(sVolume<((DWORD)0xffff/9*3))
out=3;
else if(sVolume<((DWORD)0xffff/9*4))
out=4;
else if(sVolume<((DWORD)0xffff/9*5))
out=5;
else if(sVolume<((DWORD)0xffff/9*6))
out=6;
else if(sVolume<((DWORD)0xffff/9*7))
out=7;
else if(sVolume<((DWORD)0xffff/9*8))
out=8;
else
out=9;
int x =0;
switch(out)
{
case 0:
x = 315;
break;
case 1:
x = 322;
break;
case 2:
x = 329;
break;
case 3:
x = 336;
break;
case 4:
x = 343;
break;
case 5:
x = 350;
break;
case 6:
x = 357;
break;
case 7:
x = 364;
break;
case 8:
x = 371;
break;
case 9:
x = 378;
break;
}
//为点静音按纽,保丰收当前音量。
m_VolDian.MoveWindow(x,201,14,20);
}
//
//void CPLAYMP3Dlg::ShowVolume(UCHAR volume)
//{
//
//}
//
BOOL CPLAYMP3Dlg::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
if (mSliderTimer)
{
KillTimer(mSliderTimer);
mSliderTimer = 0;
}
return CDialog::DestroyWindow();
}
HRESULT CPLAYMP3Dlg::FindFilterByInterface(REFIID riid, IBaseFilter **ppFilter)
{
*ppFilter = NULL;
if (!mFilterGraph)
{
return E_FAIL;
}
IEnumFilters* pEnum;
HRESULT hr = mFilterGraph->GetGraph()->EnumFilters(&pEnum);
if (FAILED(hr))
{
return hr;
}
IBaseFilter* pFilter = NULL;
while (pEnum->Next(1, &pFilter, NULL) == S_OK)
{
// Check for required interface
IUnknown* pUnk;
HRESULT hrQuery = pFilter->QueryInterface(riid, (void**)&pUnk);
if (SUCCEEDED(hrQuery))
{
pUnk->Release();
pEnum->Release();
*ppFilter = pFilter;
return S_OK;
}
pFilter->Release();
}
pEnum->Release();
return E_FAIL;
}
/*
void CPLAYMP3Dlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
if (pScrollBar->GetSafeHwnd() == m_SliderGraph.GetSafeHwnd())
{
}
else
{
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
}
*/
void CPLAYMP3Dlg::GetMp3INFO(CString _tempPath)
{
_WMAINFO wmainfo;
// mp3Artist = "";
// mp3Title = "";
CString _p = _tempPath.Right(4);
// CString _p2 = _p.MakeUpper();
CString _p3 = ".wma";
int i = _p.CompareNoCase(_p3);//0 为等
if (i == 0)//如果是WMA格式则有眺过。因为我没有做出来。CompareNoCase
{
mp3Title = GetWmaINFO(_tempPath) .Artist;
mp3Artist = GetWmaINFO(_tempPath) .Title;
return;
}
CFile file;
if(!file.Open(_tempPath,CFile::modeRead))
{
// AfxMessageBox(L"Can not open file.");
return ; //文件^无法打开
}
//把文件的最后128字节信息读给pbuf数组
long seekPos = 128;
file.Seek(-seekPos,CFile::end);
BYTE pbuf[128];
memset(pbuf,0,sizeof(pbuf));
file.Read(pbuf,128);
mp3Info=(MP3INFO *) new BYTE[sizeof(MP3INFO)];
ZeroMemory(mp3Info,sizeof(MP3INFO));
// memcpy(mp3Info->Identify,pbuf,3); //获得tag
memcpy(mp3Info->Title,pbuf+3,30); //获得歌名
memcpy(mp3Info->Artist,pbuf+33,30); //获得作者
/*
memcpy(mp3Info->Album,pbuf+63,30); //获得唱片名
memcpy(mp3Info->Year,pbuf+93,4); //获得年
memcpy(mp3Info->Comment,pbuf+97,28); //获得注释
memcpy(&mp3Info->reserved,pbuf+125,1); //获得保留
memcpy(&mp3Info->reserved2,pbuf+126,1);
memcpy(&mp3Info->reserved3,pbuf+127,1);
*/
mp3Title = mp3Info->Title;
mp3Artist = mp3Info->Artist;
/*
mp3Album = mp3Info->Album;
mp3Year = mp3Info->Year;
*/
file.Close();
delete mp3Info;
}
int CPLAYMP3Dlg::GetCStringLen(CString str)
{
int len = 0;
bool c = true;
int n = 0;
int l = str.GetLength();
while (c)
{
if (str.GetAt(n) > 0xa1)
{
len = len + 2;
}
else
len++;
n++;
if ( n == l)
{
c = false;
}
}
return len;
}
void CPLAYMP3Dlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
//AfxMessageBox(L"sadfasdfasdf");
if (mFilterGraph)
{
delete mFilterGraph;
mFilterGraph = NULL;
// Stop the timer
if (mSliderTimer)
{
KillTimer(mSliderTimer);
mSliderTimer = 0;
}
}
CDialog::OnOK();
}
void CPLAYMP3Dlg::OnOK()
{
// this->ShowWindow(SW_HIDE);
//
// HWND h1;
//
// h1 = ::FindWindow(TEXT("OPENPLAY"),NULL);
// if (h1 !=NULL)
// {
// ::SendMessage(h1,WM_CLOSE,0,0 );
// }
//
//
//
// HWND h;
// h = ::FindWindow(TEXT("PLAY"),NULL);
//
// if(h !=NULL)
//
// ::SendMessage(h,WM_CLOSE,0,0 );
}
HRESULT CPLAYMP3Dlg::OnSuspend()
{
HWND h1;
h1 = ::FindWindow(TEXT("OPENPLAY"),NULL);
if (h1 !=NULL)
{
::SendMessage(h1,WM_CLOSE,0,0 );
}
HWND h;
h = ::FindWindow(TEXT("PLAY"),NULL);
if(h !=NULL)
::SendMessage(h,WM_CLOSE,0,0 );
return true;
}
LRESULT CPLAYMP3Dlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
if (message == VOLMUTE)
{
DWORD dwVolume;
DWORD sVolume;
waveOutGetVolume(0, &dwVolume);
sVolume=dwVolume>>16;
if(sVolume==0)
Btn_NoVolume();
}
if (message == HIDEMP3)
{
RegCloseKey(g_hkVolume);
this->ShowWindow(SW_HIDE);
}
if (message == WM_SET_VOL)
{
b_volume = true;
int x ;
switch(wParam)
{
case 0:
x = 315;
break;
case 1:
x = 322;
break;
case 2:
x = 329;
break;
case 3:
x = 336;
break;
case 4:
x = 343;
break;
case 5:
x = 350;
break;
case 6:
x = 357;
break;
case 7:
x = 364;
break;
case 8:
x = 371;
break;
case 9:
x = 378;
break;
}
//设为非静音量,用currentVolume
m_VolDian.MoveWindow(x,201,14,20);
if (wParam > 0)
{
CopyBMP(IDB_volume,11);
}
}
if (message == SHOWMP3WINDOW)//显示歌曲信息控件。
{
m_Playing.ShowWindow(true);
m_Nameing.ShowWindow(true);
m_PlayTime.ShowWindow(true);
m_NewLrc.ShowWindow(true);
}
return CDialog::WindowProc(message, wParam, lParam);
}
_WMAINFO CPLAYMP3Dlg::GetWmaINFO(CString _strWmaPath)
{
_WMAINFO _str_Wma_info;//定义WMA信息,包括两个变量。
//return _str_Wma_info;
/*
BYTE m_Byte[16]={0x33 ,0x26,0xB2 ,0x75, 0x8E ,0x66 ,0xCF, 0x11 ,0xA6 ,0xD9, 0x00, 0xAA ,0x00 ,0x62 ,0xCE, 0x6C};//wma文件头。
char cBuffer[100];
memcpy(cBuffer,m_Byte,sizeof(m_Byte));
CString strWmaTAG= cBuffer;//得到标准的WMA前字节字符串。
*/
//////////////////////////////////////////////////////////////////
////////////////////以下十行为读WMA文件头。
CFile file11;
if(!file11.Open(_strWmaPath,CFile::modeRead))
{
file11.Close();
_str_Wma_info.Artist = " ";
_str_Wma_info.Title = " ";
return _str_Wma_info; //文件无法打开
}
long seekPos11 = 30;
bool x = true;
BYTE pbuf11[16];
while (x)
{
file11.Seek(seekPos11,CFile::begin);
memset(pbuf11,seekPos11,16);
file11.Read(pbuf11,16);
if (pbuf11 == strWmaTAG)
{
x = false;
}
seekPos11 = seekPos11 + 1;
}
TCHAR pbuf22[100];
CString strppp ;
seekPos11 = seekPos11 + 33;
file11.Seek(seekPos11,CFile::begin);
memset(pbuf22,seekPos11,100);
file11.Read(pbuf22,100);
TCHAR name1[50]={0};
TCHAR name2[50]={0};
int l =0;//读唱者
for(int i = 0;i < 100;i++)
{
if (pbuf22[i] == '\0')
{
for(int j = 0;j < i;j++)
{
name1[j] = pbuf22[j];
}
l = i+1;
break;
}
}
//读歌名。
for(int ii = l;ii < 100;ii++)
{
if (pbuf22[ii] == '\0')
{
for(int j = 0;j < ii;j++)
{
name2[j] = pbuf22[l++];
}
break;
}
}
CString na1,na2;
na1 = name1;
na2 = name2;
_str_Wma_info.Artist = name1;
_str_Wma_info.Title = name2;
// AfxMessageBox(name1);
// AfxMessageBox(name2);
file11.Close();
return _str_Wma_info;
}
void CPLAYMP3Dlg::AddToListBox()
{
int zzz = m_ListMp3.GetCount();
for(int o11 = 0;o11<zzz;o11++)
{
m_ListMp3.DeleteString(0);
}
for (int i = 0;i < openfile_dlg.array_str.GetSize(); i++)
{
// m_ListMp3.AddString(openfile_dlg.array_str.GetAt(i));
//7.19改
CString ppp = GetMp3Name(openfile_dlg.array_str.GetAt(i));
m_ListMp3.AddString(ppp);
}
}
void CPLAYMP3Dlg::OnSelchangeList()
{
// TODO: Add your control notification handler code here
m_Playing.ShowWindow(true);
m_Nameing.ShowWindow(true);
m_PlayTime.ShowWindow(true);
m_NewLrc.ShowWindow(true);
CopyBMP(IDB_PLAYMP3_W,4);
int index = m_ListMp3.GetCurSel();
CString name_ ;
// m_ListMp3.GetText(index,name_);
name_ = openfile_dlg.array_str.GetAt(index);
// mSourceFile.Format(strPath + L"mp3\\%s",name_);
mSourceFile = name_;
GetMp3INFO(mSourceFile);
b_mp3info = true;
str_lrc = "";
CString strMP3NAME,strLRCNAME;
strMP3NAME = mSourceFile.Left(mSourceFile.GetLength() - 4);
strLRCNAME = strMP3NAME + ".lrc";
lrc.Free();
if ((lrc.Open(strLRCNAME)))
{
b_yesLrc = true;
}
else
{
str_lrc = L"";
//m_lrc.SetWindowText(str_lrc);
m_NewLrc.SetWindowText(str_lrc);
// m_lrc.ShowWindow(SW_HIDE);
}
InvalidateRect(CRect(103,53,293,110),false);
mp3CreateGraph();
b_play_or_pause = true;
}
void CPLAYMP3Dlg::OnSetFocus(CWnd* pOldWnd)
{
CDialog::OnSetFocus(pOldWnd);
// TODO: Add your message handler code here
}
void CPLAYMP3Dlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(b_beginPlay)//开始播放后才可能按进度条。
if (point.x > 151 && point.x < 270 && point.y > 200 &&point.y < 220)
{
m_StateDian.MoveWindow(point.x-15 ,201,29,20);
//MOUSE抬起里,设定当前播放段//这里设不可以托了。
}
if (b_volume)
if (point.x >= 315 && point.x < 390 && point.y > 201 && point.y < 220)
{
if (point.x > 378)
{
point.x = 378;
}
m_VolDian.MoveWindow(point.x,201,14,20);
//将音量分为,85份。
DWORD dwVolume;
DWORD sVolume=((DWORD)0xffff/65*(point.x - 315));
dwVolume=(sVolume<<16)|(sVolume);
//最小声
if (point.x <= 315)
{
dwVolume = 0;
}
//最大声
if (point.x >= 375)
{
dwVolume == 0xffff;
}
waveOutSetVolume(0,dwVolume);
}
CDialog::OnMouseMove(nFlags, point);
}
//
//
//
// int all_second,all_minute;
// CString all_T;
// if (duration<60)
// {
// all_second = (int)duration;
// all_minute = 0;
// }
// else
// if (duration>=60)
// {
// all_second = (int)duration % 60;
// all_minute = (int)duration / 60;
// }
//
// all_T.Format(L"%02d:%02d");
CString CPLAYMP3Dlg::GetMp3Name(CString strName)
{
CString tempstr;
for (int i = strName.GetLength() -1 ; ; i--)
{
tempstr = strName.GetAt(i);
if (tempstr == "\\")
{
break;
}
}
CString ppp = strName.Right(strName.GetLength() -1 - i);
return ppp;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -