分类: C/C++
2008-05-31 10:04:29
void print()
{
cout<<"\n\t\t\t>>>>*简单音乐播放器*<<<<";
cout<
cout<<"*程序名称:简单音乐播放器";
cout<<"\n*编程语言:Visual C++ Window API";
cout<<"\n*软件作者:青涩橄榄";
cout<<"\n*制作时间:2006年10月14日"<
}
int main()
{
system("color 0a");
system("title 音乐播放器");
char command,b;
char filename[81];
char listname[81];
char number;
int i=1,j=1,Num;
print();
loop:
cout<<"请输入命令:\n\n>> ";
cin.get(command);
cout<
ifstream infile;
switch (command)
{
case '?':
system("cls");
cout<<"********************************************************************************";
cout<<"帮助说明:1.输入L(List)查看播放列表"<
cin.ignore (1);
Sleep(1000);
goto loop;
case 'E':
Sleep(1000);
cout<<"你确定要退出吗?(Y\\N):\n\n>> ";
cin.ignore (1);
cin.get(command);
cout<
{
cout<<"\t\t\t>>>>谢谢使用! 再见>>>>"<
return 1;
}
else
system("cls");
cin.ignore (1);
goto loop;
case 'P':
cout<<"输入文件名需要播放的歌曲文件名:\n\n>> ";
cin.ignore (1);
cin.getline (filename,80);
cout<
OpenParms.lpstrDeviceType = "mpegvideo";
OpenParms.lpstrElementName =filename;
OpenParms.wDeviceID = NULL;
mciSendCommand (NULL, MCI_OPEN,MCI_OPEN_ELEMENT, (DWORD)&OpenParms);
MCI_PLAY_PARMS PlayParms;//播放文件
PlayParms.dwFrom = 0;
mciSendCommand (OpenParms.wDeviceID, MCI_PLAY, MCI_FROM, (DWORD)&PlayParms);
cout<<"正在播放....."<
while(!infile.eof ())
{
infile.getline (str,80);
if(str[0]=='#')//去掉前面含有#的行(m3u播放列表的固有格式)
{
}
else
{
cout<<" "< i++;
}
} goto handle; goto handle; goto loop; goto handle; } case 'R': cout< system("pause"); cout< } return 0;
i=1;//将i置1,这样下次打开列表时,i还是从1开始
infile.close ();
cout<<"********************************************************************************";Sleep(1000);
cout<
cin.get (number);
cout<
{ cin.ignore (1);
cout<<"是否打开自动播放功能(Y\\N)?\n\n>> ";
cin.get(number);
cout<
cin.ignore (1);
cin>>Num;
infile.open (listname);//打开播放列表
j=1;
infile.getline (str,80);//去掉前面两行
infile.getline (str,80);
while(j<=(2*Num-3))
{
infile.getline (str,80);
j++;
}
Sleep(1000);
if(number=='Y'||number=='y')//自动播放下一首
{
while(!infile.eof())
{
j++;
infile.getline(str,80);
if(str[0]!='#')
{
Sleep(1000);
cout<
OpenParms.lpstrDeviceType = "mpegvideo";
OpenParms.lpstrElementName =str;
OpenParms.wDeviceID = NULL;
mciSendCommand (NULL, MCI_OPEN,MCI_OPEN_ELEMENT, (DWORD)&OpenParms);
MCI_PLAY_PARMS PlayParms;//播放文件
PlayParms.dwFrom = 0;
mciSendCommand (OpenParms.wDeviceID, MCI_PLAY,MCI_WAIT, (DWORD)&PlayParms);
}
}
infile.close ();
}else//不自动播放
{
play1: infile.close ();
infile.open (listname);
infile.getline (str,80);//去掉前面两行
infile.getline (str,80);
cout<
cin.ignore(1);
cin>>Num;
for(j=1;j<=(2*Num-1);j++)
{
infile.getline (str,80);
}
Sleep(1000);
cout<
OpenParms.lpstrDeviceType = "mpegvideo";
OpenParms.lpstrElementName =str;
OpenParms.wDeviceID = NULL;
mciSendCommand (NULL, MCI_OPEN,MCI_OPEN_ELEMENT, (DWORD)&OpenParms);
MCI_PLAY_PARMS PlayParms;//播放文件
PlayParms.dwFrom = 0;
mciSendCommand (OpenParms.wDeviceID, MCI_PLAY, MCI_FROM, (DWORD)&PlayParms);
handle: cout<
cin.ignore (1);
cin.get (b);
switch (b)
{
case 'S':
mciSendCommand (OpenParms.wDeviceID, MCI_STOP, NULL, NULL);
Sleep(1000);
cout<
case 'P':
MCI_PLAY_PARMS PlayParms;//播放文件
PlayParms.dwFrom = 0;
mciSendCommand (OpenParms.wDeviceID, MCI_PLAY, MCI_FROM, (DWORD)&PlayParms);
Sleep(1000);
cout<
case 'E':
mciSendCommand (OpenParms.wDeviceID, MCI_STOP, NULL, NULL);
system("cls");
print();
case 'N':
mciSendCommand (OpenParms.wDeviceID, MCI_STOP, NULL, NULL);
goto play1;
default:
Sleep(1000);
cout<<"没有这个命令......"<
}
}
else
cin.ignore (1);
goto loop;
cin.ignore (1);
goto loop;
case 'A':
system("pause");
cin.ignore (1);
goto loop;
case 'S':
cin.ignore (1);
goto loop;
case 'N':
cin.ignore (1);
goto loop;
default:
cout<
Sleep(1000);
goto loop;
}
这些代码还没有写完,而已很乱,后来自已都不知道怎么写下去了,反正就是自已觉得无聊的时候,东拼西凑搞成的,还真的能播放,支持播放列表....