Chinaunix首页 | 论坛 | 博客
  • 博客访问: 18689398
  • 博文数量: 7460
  • 博客积分: 10434
  • 博客等级: 上将
  • 技术积分: 78178
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-02 22:54
文章分类

全部博文(7460)

文章存档

2011年(1)

2009年(669)

2008年(6790)

分类: C/C++

2008-05-31 10:04:29

 #include
    #include
    #include
    #include
    #pragma comment(lib,"winmm.lib")

    void print()
    {
        cout<<"\n\t\t\t>>>>*简单音乐播放器*<<<<";
     cout<     cout<<"********************************************************************************";
        cout<<"*程序名称:简单音乐播放器";
     cout<<"\n*编程语言:Visual C++ Window API";
     cout<<"\n*软件作者:青涩橄榄";
     cout<<"\n*制作时间:2006年10月14日"<       cout<<"*软件说明:"<     cout<<"     1.输入L(List)查看播放列表"<        cout<<"     2.输入?查看帮助信息"<        cout<<"     3.输入P(Play)加歌曲代号播放歌曲"<        cout<<"     4.输入S(Stop)停止播放当前歌曲"<        cout<<"     5.输入A(Pause)暂停播放当前歌曲"<        cout<<"     6.输入N(Next)播放下一首歌曲"<        cout<<"     7.输入R(Pre)播放上一首歌曲"<        cout<<"     8.输入E(Exit)退出程序"<        cout<<"********************************************************************************"<     Sleep(1000);
    }
    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<     system("cls");
     ifstream infile;

     switch (command)
     {
     case '?':
        system("cls");
        cout<<"********************************************************************************";
        cout<<"帮助说明:1.输入L(List)查看播放列表"<              cout<<"         2.输入?查看帮助信息"<              cout<<"         3.输入P(Play)加歌曲代号播放歌曲"<              cout<<"         4.输入S(Stop)停止播放当前歌曲"<              cout<<"         5.输入P(Pause)暂停播放当前歌曲"<              cout<<"         6.输入N(Next)播放下一首歌曲"<              cout<<"         7.输入P(Pre)播放上一首歌曲"<              cout<<"         8.输入E(Exit)退出程序"<           cout<<"********************************************************************************";
              cin.ignore (1);
        Sleep(1000);
        goto loop;
        case 'E':
      Sleep(1000);
      cout<<"你确定要退出吗?(Y\\N):\n\n>> ";
      cin.ignore (1);
      cin.get(command);
      cout<      if(command=='Y'||command=='y')
      {
       cout<<"\t\t\t>>>>谢谢使用! 再见>>>>"<       Sleep(3000);
       return 1;
      }
       else
       system("cls");
          cin.ignore (1);
       goto loop;
        case 'P':
      cout<<"输入文件名需要播放的歌曲文件名:\n\n>> ";
      cin.ignore (1);
      cin.getline (filename,80);
      cout<      MCI_OPEN_PARMS OpenParms;//打开设备
            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<<"正在播放....."<    halt: cout<> ";

cin.get (b);
     switch (b)
      {
      case 'S':
       mciSendCommand (OpenParms.wDeviceID, MCI_STOP, NULL, NULL);
       Sleep(1000);
       cout<       cin.ignore (1);
       goto halt;
      case 'P':
       MCI_PLAY_PARMS PlayParms;//播放文件
                PlayParms.dwFrom = 0;
                mciSendCommand (OpenParms.wDeviceID, MCI_PLAY, MCI_FROM, (DWORD)&PlayParms);
                Sleep(1000);
                cout<       cin.ignore (1);
       goto halt;
      case 'E':
       mciSendCommand (OpenParms.wDeviceID, MCI_STOP, NULL, NULL);
       system("cls");
       print();
       cin.ignore (1);
       goto loop;
      default:
       Sleep(1000);
       cout<<"没有这个命令......"<       goto halt;
      }
     case 'L':
         char str[81];
      cout<<"你要打开的播放列表是(M3U):\n\n>> ";
      cin.ignore (1);
      cin.getline(listname,80);
      infile.open (listname);
      if(!infile)
      {
          Sleep(1000);
       cout<<"文件读取错误!\a"<          goto loop;
      }
          else
      cout<<"********************************************************************************";
      cout<<"歌曲列表如下:"<      Sleep(1000);

         while(!infile.eof ())
      {
          infile.getline (str,80);
       if(str[0]=='#')//去掉前面含有#的行(m3u播放列表的固有格式)
       {
       }
       else
       {
        cout<<"    "<           i++;
       }

      }
      i=1;//将i置1,这样下次打开列表时,i还是从1开始
      infile.close ();
      cout<<"********************************************************************************";Sleep(1000);
      cout<> ";
         cin.get (number);
      cout<      if(number=='Y'||number=='y')
      {   cin.ignore (1);
       cout<<"是否打开自动播放功能(Y\\N)?\n\n>> ";
       cin.get(number);
       cout<                cout<<"你想播放第几首歌曲?\n\n>> ";
       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<        MCI_OPEN_PARMS OpenParms;//打开设备
                    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<       MCI_OPEN_PARMS OpenParms;//打开设备
                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<

       goto handle;
      case 'P':
       MCI_PLAY_PARMS PlayParms;//播放文件
                PlayParms.dwFrom = 0;
                mciSendCommand (OpenParms.wDeviceID, MCI_PLAY, MCI_FROM, (DWORD)&PlayParms);
                Sleep(1000);
                cout<

       goto handle;
      case 'E':
       mciSendCommand (OpenParms.wDeviceID, MCI_STOP, NULL, NULL);
       system("cls");
       print();

       goto loop;
      case 'N':
          mciSendCommand (OpenParms.wDeviceID, MCI_STOP, NULL, NULL);
       goto play1;
      default:
       Sleep(1000);
       cout<<"没有这个命令......"<

       goto handle;
      }

      }
      }
       else
        cin.ignore (1);
                    goto loop;

     case 'R':

      cout<      Sleep(1000);
         cin.ignore (1);
      goto loop;
     case 'A':
         system("pause");
      cin.ignore (1);
      goto loop;
     case 'S':

      system("pause");
      cin.ignore (1);
      goto loop;
     case 'N':

      cout<      Sleep(1000);
      cin.ignore (1);
      goto loop;
     default:
      cout<      cin.ignore (1);
      Sleep(1000);
         goto loop;

     }

    return 0;
    }
    这些代码还没有写完,而已很乱,后来自已都不知道怎么写下去了,反正就是自已觉得无聊的时候,东拼西凑搞成的,还真的能播放,支持播放列表....

阅读(861) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~