立即注册 登录
返回首页

uid:63663的个人空间

日志

播放器

已有 838 次阅读2014-9-3 18:51 | 资料

#include "head.h"

play_number = 1;

int main(int argc,char *argv[])
{
 char key = 0;
 int play_way = 0;    //播放还是暂停????1播放,0暂停
////关于名字动态显示////////////////////////////////////////////////////////////
 int i = 0;
 int j = 0;
 char display_text[11] = {0};
 int text_len = 0;
 char *h = NULL;
 int delay_sign = 1;
 int m = 0;//////////////////////////////////////////////////// 
 unsigned long delay_count1 = 0; 
// int delay_count2 = 0;
 int go_step = 0; 
 char buff1[200] = {0};
 char *ch = NULL;
 music_one * play_this = NULL;
 int play_mode = 1;    //播放模式  0单曲?1顺序?2随机?
 int sub = 4;          //频谱减
 int sup = 0;          //加
 int up_lock = 0;
 int down_lock = 1;

//////////////////////////////////////////////////////////////////////////
/*         关于时间显示         */
 char buff_time_display[50] = {0};
 char buff_time_display2[50] = {0};
 long mytime_1 = 0;
 int  mytime_minute = 0;
 int  mytime_second = 0;
///////////关于当前时间////////////////////////////////////////////////
 char buff_time_now[50] = {0};
 char buff_time_now2[50] = {0};
 long mytime_now = 0;
 int  mytime_minute_now = 0;
 int  mytime_second_now = 0;
/////////////关于进度条////////////////////////////////////////////////////
 double my_program = 0;
 int go = 0;
/////////////关于音量///////////////////////////////////////////////////
 char my_volume_buf[100] = {0};
 int my_volume_var = 300;
 char my_volume_buff[50] = {0};
//////////////////////////////////////////////////////////////////////////
 initialization();
 head = (music_head *)malloc(sizeof(music_head));
 memset(head, 0, sizeof(music_head)); 
 
//获取当前播放器路径
 strcpy(program_direct, argv[0]);
//读取程序所在文件夹中MP3文件个数
 read_file_count(head);
 gotoxy(X(10),Y(4));
 printf("/%d", head->music_count);
//建链表
 list_creat(head);
//读文件
 read_file(head);
 list_output(head);
 play_name_lock = 1;
 TEXT_RED;
 gotoxy(X(6),Y(6));
 printf("%3d", my_volume_var/10);
 gotoxy(X(14),Y(6)); 
 printf("%s","顺序");
 while(1)
 {
  while (!_kbhit())
  { 
///////////////显示动态名字/////////////////////////////////////////////////////////////// 
   play_this = head->next; 
   while(play_number != play_this->music2_number)
   {
    play_this = play_this->next;
   }   
   sprintf(buff1,"%s%s%s", "          ", play_this->music1_name, "    ");   
   ch = buff1; 
   while(*ch++); 
   text_len  = ch - buff1;             //得到字符串长度
   go_step =  (text_len - 8)/2;        
   if(delay_sign == 1)
   {  
    delay_sign = 0;
    i = i % text_len;
    i = i + 2;
   }   
    gotoxy(X(12), Y(4));
    for (j = 0; j < 10; j++)
    {
     display_text[j] = buff1[j+i];
    }
                //延时计数,计数到100后打印
    if (delay_count1 == 100)    //计数器到每到一百显示一次
    {
     delay_sign = 1;         //显示完一次,为下一次字符串移动准备
     TEXT_BRIGHT_GREEN;
     printf("%s", display_text);
     TEXT_RED;
     delay_count1 = 0;
//     delay_count2 ++;
    }  
    delay_count1++;
    Sleep(2);
/////////////////歌曲总时间长度///////////////////////////////////////////////////////////   
    //以字符串的方式得到歌曲总时间
    sprintf(buff_time_display, "%s %s %s", "Status", play_this->music1_name, "length");
    mciSendString(buff_time_display, buff_time_display2, sizeof(buff_time_display2), NULL);
    mytime_1 = strtol(buff_time_display2, NULL, 10);    
    mytime_second = mytime_1/1000 % 60;
    mytime_minute = mytime_1/1000 /60;
    gotoxy(X(37),Y(13));
    printf("%d:%d", mytime_minute, mytime_second);
/////////////////显示歌曲现在进度///////////////////////////////////////////////////////////        
    sprintf(buff_time_now, "%s %s %s", "Status", play_this->music1_name, "position");
    mciSendString (buff_time_now, buff_time_now2, sizeof(buff_time_now2), NULL);
    mytime_now = strtol(buff_time_now2, NULL, 10);    
    mytime_second_now = mytime_now/1000 % 60;
    mytime_minute_now = mytime_now/1000 /60;
    gotoxy(X(34),Y(13));
    printf("%d:%2d /", mytime_minute_now, mytime_second_now);   
/////////////////进度条显示///////////////////////////////////////////////////////////
       my_program = mytime_1/60;          //应该每过这个时间进度条向前走一次    
    if (my_program * go < mytime_now)
    {
     go++;
     gotoxy(10+go, Y(13));
        printf("%s", "=>");
    }
/////////////////关于音量///////////////////////////////////////////////////////////
    sprintf(my_volume_buf, "%s %s %s %d", "setaudio",
              play_this->music1_name, "volume to", my_volume_var);
    mciSendString(my_volume_buf, my_volume_buf, sizeof(my_volume_buf), NULL);
/////////////////显示频谱///////////////////////////////////////////////////////////
    if(delay_count1 % 20 == 19)
    {
     if ((1 == down_lock) && (1 == play_way))
     {
      gotoxy(X(18),Y(10-sup));
      printf("=");
      gotoxy(X(19),Y(8-sup));
      printf("=");
      gotoxy(X(20),Y(7-sup));
      printf("=");
      gotoxy(X(21),Y(9-sup));
      printf("=");
      gotoxy(X(22),Y(11-sup));
      printf("=");
      gotoxy(X(23),Y(10-sup));
      printf("=");
      gotoxy(X(24),Y(11-sup));
      printf("=");
      gotoxy(X(25),Y(9-sup));
      printf("=");
      gotoxy(X(26),Y(10-sup));
      printf("=");
      gotoxy(X(27),Y(8-sup));
      printf("=");
      if(sup == 4)
      {
       down_lock = 0;
       up_lock = 1;
       sup = 0;
      }
      sup ++;
     }
     if ((1 == up_lock) && (1 == play_way))
     {        
      gotoxy(X(18),Y(9-sub));
      printf(" ");
      gotoxy(X(19),Y(7-sub));
      printf(" ");
      gotoxy(X(20),Y(6-sub));
      printf(" ");
      gotoxy(X(21),Y(8-sub));
      printf(" ");
      gotoxy(X(22),Y(10-sub));
      printf(" ");
      gotoxy(X(23),Y(9-sub));
      printf(" ");
      gotoxy(X(24),Y(10-sub));
      printf(" ");
      gotoxy(X(25),Y(8-sub));
      printf(" ");
      gotoxy(X(26),Y(9-sub));
      printf(" ");
      gotoxy(X(27),Y(7-sub));
      printf(" ");
      if(sub == 0)
      {
       down_lock = 1;
       up_lock = 0;
       sub = 4;
      }
      sub --;            
     }
    }
/////////////////播放模式控制///////////////////////////////////////////////////////////
    if ((mytime_1 - mytime_now) < 2000)
    {
     switch(play_mode)
     {
     case 0:            //单曲循环      
      play_num_song("stop", play_number, head);
         play_number--; 
      goto _nextmusic;      
      break;
     case 1:            //顺序播放
      play_num_song("stop", play_number, head);
      goto _nextmusic;
      break;      
     case 2:            //随机播放
      play_num_song("stop", play_number, head);
      play_number = delay_count1 % head->music_count - 1;
      goto _nextmusic;
      break;
     }
    }
///////////当有键按下/////////////////////////////////////////////////////////////////
  }
   key = _getch();
   up_lock = 1;
   switch (key)
   {
   case 'n':     //向下翻页
    list_output(head);
    break;
   case ' ':     //暂停和开始
    if (play_way == 0)
    {
     play_way = 1;
     play_num_song("play", play_number, head);
    }
    else
    {
     play_way = 0;
     play_num_song("pause", play_number, head);
    }
    
    break;
   case 'h':   //下一曲     
_nextmusic:
    play_way = 1;
    if (play_number < head->music_count)
    {

      TEXT_GREEN;
      for (i = 3; i < 33; i++)       //进度条初始
      {
       go = 0;
       SOMEPLACE_PRINT(X(i), Y(13), "--");  
      }
      TEXT_RED;
     play_num_song("stop", play_number, head);
     play_number++; 
     play_num_song("play", play_number, head);
    }
    else
    {
         TEXT_GREEN;
      for (i = 3; i < 33; i++)       //进度条初始
      {
       go = 0;
       SOMEPLACE_PRINT(X(i), Y(13), "--");  
      }
      TEXT_RED;
     play_num_song("stop", play_number, head);
     play_number = head->music_count;
     play_num_song("play", play_number, head);
     break;
    } 
    break;
   case 'g':    //上一曲
    play_way = 1;
    if (play_number > 2)
    {
     play_num_song("stop", play_number, head);
     play_number -= 2;
     goto _nextmusic;
        break;
    }
    else
    {//处理弟一首歌
     play_num_song("stop", 2, head);
     play_number = 1;
     TEXT_GREEN;
     for (i = 3; i < 33; i++)       //进度条初始
     {
      go = 0;
      SOMEPLACE_PRINT(X(i), Y(13), "--");  
     }
     TEXT_RED;     
     play_num_song("play", 1, head);
    }
    break;
   case 'f':
    play_way = 1;
    play_num_song("stop", play_number, head);
    play_number = 1;
    TEXT_GREEN;
    for (i = 3; i < 33; i++)       //进度条初始
    {
     go = 0;
     SOMEPLACE_PRINT(X(i), Y(13), "--");  
    }
    TEXT_RED;     
    play_num_song("play", play_number, head);
    break;
   case 'j':
    play_way = 1;
    play_num_song("stop", play_number, head);
    play_number = head->music_count;
    TEXT_GREEN;
    for (i = 3; i < 33; i++)       //进度条初始
    {
     go = 0;
     SOMEPLACE_PRINT(X(i), Y(13), "--");  
    }
    TEXT_RED;     
    play_num_song("play", play_number, head);
    break;
   case 'v':     //音量加
    gotoxy(X(6), Y(6));
    printf("%3d", my_volume_var/10);
    if (my_volume_var < 1000)
    {
     my_volume_var += 50;
    }    
    break;
   case 'c':      //音量减
    gotoxy(X(6),Y(6));
    printf("%3d", my_volume_var/10);
    if (my_volume_var > 0)
    {
     my_volume_var -= 50;
    }    
    break;
   case 'm':
    play_mode++;
    play_mode = play_mode % 3;
    gotoxy(X(14),Y(6));
    if (0 == play_mode)
    {
     printf("%s","单曲");
    }
    else if (1 == play_mode)
    {
     printf("%s","顺序");
    }
    else
    {
     printf("%s","随机");
    }
   case '1':
    if (head->music_count >= 1)
    {
    play_way = 1;
     TEXT_GREEN;
     for (i = 3; i < 33; i++)       //进度条初始
     {
      go = 0;
      SOMEPLACE_PRINT(X(i), Y(13), "--");  
     }
     TEXT_RED;
     play_num_song("stop", play_number, head);
     play_number = arr_number[1]; 
     play_num_song("play", play_number, head);
    }
    break;
   case '2':
    if (head->music_count >= 2)
    {
    play_way = 1;
    TEXT_GREEN;
    for (i = 3; i < 33; i++)       //进度条初始
    {
     go = 0;
     SOMEPLACE_PRINT(X(i), Y(13), "--");  
    }
    TEXT_RED;
    play_num_song("stop", play_number, head);
    play_number = arr_number[2]; 
    play_num_song("play", play_number, head);
    }
    break;
   case '3':
    if (head->music_count >= 3)
    {
    play_way = 1;
    TEXT_GREEN;
    for (i = 3; i < 33; i++)       //进度条初始
    {
     go = 0;
     SOMEPLACE_PRINT(X(i), Y(13), "--");  
    }
    TEXT_RED;
    play_num_song("stop", play_number, head);
    play_number = arr_number[3]; 
    play_num_song("play", play_number, head);
    }
    break;
   case '4':
    if (head->music_count >= 4)
    {
    play_way = 1;
    TEXT_GREEN;
    for (i = 3; i < 33; i++)       //进度条初始
    {
     go = 0;
     SOMEPLACE_PRINT(X(i), Y(13), "--");  
    }
    TEXT_RED;
    play_num_song("stop", play_number, head);
    play_number = arr_number[4]; 
    play_num_song("play", play_number, head);
    }
    break;
   case '5':
    if (head->music_count >= 5)
    {
    play_way = 1;
    TEXT_GREEN;
    for (i = 3; i < 33; i++)       //进度条初始
    {
     go = 0;
     SOMEPLACE_PRINT(X(i), Y(13), "--");  
    }
    TEXT_RED;
    play_num_song("stop", play_number, head);
    play_number = arr_number[5]; 
    play_num_song("play", play_number, head);
    }
    break;
   case '6':
    if (head->music_count >= 6)
    {
    play_way = 1;
    TEXT_GREEN;
    for (i = 3; i < 33; i++)       //进度条初始
    {
     go = 0;
     SOMEPLACE_PRINT(X(i), Y(13), "--");  
    }
    TEXT_RED;
    play_num_song("stop", play_number, head);
    play_number = arr_number[6]; 
    play_num_song("play", play_number, head);
    }
    break;
   case '7':
    if (head->music_count >= 7)
    {
    play_way = 1;
    TEXT_GREEN;
    for (i = 3; i < 33; i++)       //进度条初始
    {
     go = 0;
     SOMEPLACE_PRINT(X(i), Y(13), "--");  
    }
    TEXT_RED;
    play_num_song("stop", play_number, head);
    play_number = arr_number[7]; 
    play_num_song("play", play_number, head);
    }
    break;
   case '8':
    if (head->music_count >= 8)
    {
    play_way = 1;
    TEXT_GREEN;
    for (i = 3; i < 33; i++)       //进度条初始
    {
     go = 0;
     SOMEPLACE_PRINT(X(i), Y(13), "--");  
    }
    TEXT_RED;
    play_num_song("stop", play_number, head);
    play_number = arr_number[8]; 
    play_num_song("play", play_number, head);
    }
    break;
   case '9':
    if (head->music_count >= 9)
    {
    play_way = 1;
    TEXT_GREEN;
    for (i = 3; i < 33; i++)       //进度条初始
    {
     go = 0;
     SOMEPLACE_PRINT(X(i), Y(13), "--");  
    }
    TEXT_RED;
    play_num_song("stop", play_number, head);
    play_number = arr_number[9]; 
    play_num_song("play", play_number, head);
    }
    break;
   default:
    break;
  }
 }
 mciSendString("close", NULL, 0, NULL);
 list_delete(head);
 return 0;
}


路过

鸡蛋

鲜花

握手

雷人

全部作者的其他最新日志

评论 (0 个评论)

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

返回顶部