📄 mp3.c
字号:
#include <stdio.h>
#include <time.h>
#include <windows.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
#include <mmsystem.h>
#include <io.h>
#include <tcconio.h>
int _chdir(const char *dirname);
int enter_path();
void Usage();
void Play();
void Stop();
void Pause();
void Resume();
void Speed();
void Position(); /* Prototipi na vsichki funkci */
void GetAllSong();
void StatSong();
void CloseSong();
void init();
void AutoP_List();
void p_NextList();
void p_PrevList();
void GetOldColor();
void GetSongLength();
void GetTotalTimeAllSong();
void GetTimeAddSong();
void GetTimeDelSong();
void write_data();
void Quit();
#define max_num 1000
const char file_path[128] = "path.txt";
char old_path[128];
char NextSong[max_num][128];
char ShortPathName[max_num][80];
char LongFileName[max_num][128]; /* Vsichki 2-merni i 3-merni masivi */
char CompareNames[max_num][128];
char p_List[15][10][128];
char p_file[15][10][128];
char Label[128]; /* vischki ednomerni masivi */
char UserName[128];
char speed[128];
char dirname[128];
int i,s,p;
int a,b,v;
int err;
int isPlay; /* Vsichki celochisleni promenlivi */
int Control;
int TotalSong;
int p_count;
int a_uto;
int m_null;
int num;
int MAX;
unsigned getlen;
int number[max_num];
int mm_time;
int stop_flash;
int m_normal_text;
int p_change;
int y[1000];
int x = 25;
int h2,m2,s2;
int main(void){ /* nachalo na programata */
int ret;
FILE *in;
struct _finddata_t f;
clrscr();
DWORD nUserName = sizeof(UserName); /* Vzemane na user name */
if (GetUserName(UserName, &nUserName) == 0) {
printf("Failed to lookup user name, error code ",GetLastError());
}
clrscr();
memset(dirname,'\0',sizeof(dirname));
if ((ret = _findfirst("*.mp3",&f)) < 0){
for(;;){
GetCurrentDirectory(256, old_path);
if ((in = fopen(file_path,"rb")) == NULL) {
enter_path();
break;
}
fread((void*)&dirname,sizeof(char),128,in);
fclose(in);
break;
}
}
GetAllSong(); /* Zarejdane na pesnite v masiva */
init(); /* initializirane na play listata */
/* Prochitane na niakoi failove koito sadarjat informacia za mp3 file(s) */
FILE *p;
if ((p = fopen("length.txt","rb")) == NULL) {
GetTotalTimeAllSong();
goto label1;
}
if(p){
fscanf(p,"%d %d %d %d %d",&h2,&m2,&s2,&mm_time,&getlen);
fclose(p);
}
if ((p = fopen("number.txt","rb")) == NULL) goto label1;
if(p){
for(int f=0;f<mm_time;f++) {
fread((void*)&number[f],sizeof(int),1,p);
}
fclose(p);
}
if ((p = fopen("names.txt","rb")) == NULL) goto label1;
if(p){
for(int f=0;f<TotalSong;f++){
fread((void*)&CompareNames[f],sizeof(char),1024,p);
}
fclose(p);
}
if(TotalSong > mm_time) GetTimeAddSong();
if(TotalSong < mm_time) GetTimeDelSong();
label1:
Play(); /* Prosfirvane na parvia file ot masiva s dani */
Usage(); /* glavno menu za user */
return 0;
}
int enter_path() {
int i;
int a1,b1;
int ret;
char str[128];
char ch;
FILE *out;
clrscr();
memset(str,'\0',sizeof(str));
gotoxy(1,25);
printf("MP3 Pro v 2.0 copyright (C) 2002.Press Esc to exit.");
gotoxy(1,2);
printf("Enter path to your mp3 song(s): ");
i = 0;
while(1) {
ch = getch();
if (ch == 27) return -1;
if (ch == 13) {
if (i == 0) continue;
break;
}
if (ch == 8) {
str[i] = '\0';
i--;
if (i < 0) {
i = 0;
continue;
}
clrscr();
gotoxy(1,25);
printf("Mp3 Pro v 2.0 copyright (C) 2003.Press Esc to exit.");
gotoxy(1,2);
printf("Enter path to your mp3 song(s): ");
for (a1=0;a1<i;a1++) printf("%c",str[a1]);
}
if (ch != 8 && ch != 13 && ch !=27 && ch != 9) {
str[i] = ch;
i++;
if (i > 20) {
i = 20;
continue;
}
gotoxy(33,2);
for (b1=0;b1<i;b1++) printf("%c",str[b1]);
}
}
if ((ret = _chdir(str)) < 0) { /* Provarka za validen pat example d:\music\2003 */
gotoxy(33,15);
printf("Path is not valid!");
getch();
return -1;
}
_chdir(old_path);
strcpy(dirname,str);
if ((out = fopen(file_path,"wb")) == NULL) exit(1); /* Zapisvame dirname v path.txt */
fprintf(out,"%s",dirname);
fclose(out);
return 0;
}
void Usage(){
char ch;
int max_len = 0;
int i;
FILE *in;
clrscr();
textcolor(7);
gotoxy(18,1);
printf("Mp3 Pro v 2.0 Programed by Nikolai Halachev BG.");
gotoxy(18,2);
printf("Free MP3 player for windows (95,98)");
gotoxy(1,5);
printf(" P = Play\n");
printf(" S = Stop\n");
printf(" W = Pause\n");
printf(" X = Change Speed\n");
printf(" C = Change Position\n");
printf(" -> = Next Song\n");
printf(" <- = Prev Song\n");
printf(" L = Load Song(s)\n");
printf(" Q = Quit");
gotoxy(1,20);
printf(" TotalSong = %d",TotalSong);
gotoxy(1,15);
printf(" Enter your choice: ");
textcolor(12);
gotoxy(39,4);
printf(" Play List");
textcolor(7);
if(TotalSong > 9){
textcolor(15);
gotoxy(25,15);
printf("Press (+) to next Play List or (-) to prev Play List");
textcolor(7);
}
max_len = TotalSong / 9;
gotoxy(50,4);
printf("[%d]",p_count+1);
/* Pokazvane na parvite 9 pesni */
for (int q=0;p_List[p_count][q][0];q++){
y[q] = 5 + q;
gotoxy(x,y[q]);
clreol();
printf("%d. %s",q+1,p_List[p_count][q]);
}
/* cikal za sledene sastoianieto na pesenta i oshte drugi */
while(1){
for(;;) {
StatSong(); /* sledene sastoianieto na pesenta */
GetSongLength();/*Vzimane na daljinata na pesenta */
if (!isPlay) {
/* Ako poslednata play lista isviri poslednota pesen vzemi parvata play lista */
if (p_count == max_len){
if(!strcmp(p_List[p_count][num+1],"")){
p_count = -1;
p_NextList();
num = -1;
}
}
/* Ako a_uto = 9 poslednata pozicia ot play lista avtomatichna smiana na play listata */
if(a_uto) {
AutoP_List();
num = -1;
a_uto = 0;
}
if(num == 8){
AutoP_List();
num = -1;
}
GetOldColor();
CloseSong();
num++;
Play();
}
textcolor(7);
gotoxy(2,21);
printf("User Name: ");
printf("%s",UserName);
if(kbhit()) break;
sleep(100);
if (Control) {
gotoxy(1,23);
clreol();
printf(" Stoped -> %s ",Label);
}
if (!Control) {
gotoxy(1,23);
clreol();
printf(" Playing -> %s ",Label);
}
gotoxy(55,21);
printf("Copyright (C) 2003");
}
ch = getch();
/* Prehvashtane na klavish ot user za barz dostap do file(mp3) */
int hot_key = 0;
char *s_key;
s_key = (char*)malloc(100);
s_key[0] = ch;
hot_key = atoi(s_key);
/* Ako sme v poslednata Play Lista i imame 4 pesni naprimer ne dopuskame 5 pesen */
if (p_count == max_len){
if(!strcmp(p_List[p_count][hot_key-1],"")) goto label1;
}
/* End */
/* Obrabotka na klavisha za barz dostap */
if( hot_key > TotalSong) goto label1;
if (hot_key){
if(hot_key == 9) a_uto = 1;
if(hot_key < 9) a_uto = 0;
num = hot_key - 1;
CloseSong();
Play();
if(m_null) goto label1;
GetOldColor();
}
label1:
m_null = 0;
Control = 0;
if (tolower(ch) == 'p') {
CloseSong();
Play();
}
if (tolower(ch) == 's') Stop(); /* Izvikvane na funk Stop */
if (tolower(ch) == 'w') Pause(); /* izvikvane na funk Pause */
if (tolower(ch) == 'x') Speed(); /* Izvikvane na funk Speed */
if (tolower(ch) == 'c') Position(); /* izvikvane na funk Position */
if (tolower(ch) == 'l') { /* Zarejdane na nova diriktoria ot mp3-ki */
_chdir(old_path);
if((i = enter_path()) < 0) Usage();
_chdir(dirname);
/* Initializirane na niakoi globalni promenlivi ot razlichen tip */
memset(NextSong,'\0',sizeof(NextSong));
memset(CompareNames,'\0',sizeof(CompareNames));
memset(ShortPathName,'\0',sizeof(ShortPathName));
memset(LongFileName,'0',sizeof(LongFileName));
memset(p_List,'\0',sizeof(p_List));
memset(p_file,'\0',sizeof(p_file));
p_count = 0;
m_null = 0;
mm_time = 0;
GetAllSong();
GetTotalTimeAllSong();
init();
_chdir(old_path);
Play();
Usage();
}
if (ch == '=') p_NextList(); /* Obhojdane na play listata napred */
if (ch == '-') p_PrevList(); /* Obhojdane na play listata nazad */
if (ch == 0x4d) {
CloseSong();
num++;
int bc;
for (bc=0;p_List[p_count][bc][0];bc++);
if (num > bc-1) {
p_NextList();
p_change = 1;
a_uto = 0;
num = 0;
}
GetOldColor();
isPlay = 0;
Play();
}
if (ch == 0x4b){
CloseSong();
num--;
isPlay = 1;
GetOldColor();
Play();
}
if (tolower(ch) == 'q') Quit();
}
}
void Play() {
char FileName[128];
_chdir(dirname);
if (!isPlay) {
strcpy(FileName,"open ");
strcat(FileName,NextSong[num]);
strcat(FileName," alias song");
strcpy(speed,"set song speed ");
strcat(speed,"1000");
strcpy(Label,p_List[p_count][num]);
}
if (isPlay){
if (num < 0 ) num = 0;
strcpy(FileName,"open ");
strcat(FileName,NextSong[num]);
strcat(FileName," alias song");
strcpy(speed,"set song speed ");
strcat(speed,"1000");
strcpy(Label,p_List[p_count][num]);
}
err = mciSendString(FileName,0,0,0);
if (err > 0 ) {
perror("error");
exit(1);
}
err = mciSendString(speed,0,0,0);
if (err > 0) {
perror("error");
exit(1);
}
err = mciSendString("play song",0,0,0);
if (err > 0) {
perror("error");
exit(1);
}
if(p_change) {
strcpy(Label,p_List[p_count][0]);
p_change = 0;
}
if(!strcmp(Label,"")) strcpy(Label,LongFileName[0]);
}
void Stop(){
err = mciSendString("stop song",0,0,0);
Control = 1;
if (err > 0) {
perror("error");
exit(1);
}
}
void Pause(){
char ch;
err = mciSendString("pause song",0,0,0);
if (err > 0) {
perror("error");
exit(1);
}
gotoxy(1,23);
clreol();
printf(" Paused -> %s ",Label);
while(1){
ch = getch();
if (tolower(ch) == 'w') {
gotoxy(1,23);
clreol();
printf(" Playing -> %s ",Label);
Resume();
break;
}
}
}
void Resume(){
err = mciSendString("resume song",0,0,0);
if (err > 0) {
perror("error");
exit(1);
}
}
void Speed() {
char Stat[20];
char bit[128];
char str[128];
char ch;
stop_flash = 1;
memset(str,'\0',sizeof(str));
clrscr();
strcpy(bit,"set song speed ");
gotoxy(1,25);
printf("MP3 Pro v 2.0 copyright (C) 2002.Press Esc to exit.");
gotoxy(1,2);
printf("Change speed: ");
i = 0;
while(1) {
for (;;) {
mciSendString("status song mode",Stat,128,0);
StatSong();
if (!isPlay) Usage();
if (kbhit()) break;
}
ch = getch();
if (ch == 27) {
stop_flash = 0;
Usage();
}
if (ch == 13) {
if (i == 0) continue;
break;
}
if (ch == 8) {
str[i] = '\0';
i--;
if (i < 0) {
i = 0;
continue;
}
clrscr();
gotoxy(1,25);
printf("MP3 Pro v 2.0 copyright (C) 2002.Press Esc to exit.");
gotoxy(1,2);
printf("Change speed: ");
for (a=0;a<i;a++) printf("%c",str[a]);
}
if (ch != 8 && ch != 13 && ch !=27 && ch != 9) {
str[i] = ch;
i++;
if (i > 3) {
i = 3;
continue;
}
gotoxy(15,2);
for (b=0;b<i;b++) printf("%c",str[b]);
}
}
if (i == 3) str[i] = '0';
if (i == 2) {
str[i+1] = '\0';
str[i] = '0';
}
strcat(bit," ");
strcat(bit,str);
int song_length = atoi(str);
song_length = song_length / 10;
if(song_length > 200) {
gotoxy(20,10);
printf("Speed is large maximum change of speed = 200");
getch();
Speed();
}
err = mciSendString(bit,0,0,0);
if (err > 0) {
perror("error");
exit(1);
}
stop_flash = 0;
Usage();
}
void Position() {
char Stat[20];
char ch;
char change[128];
char str[128];
memset(str,'\0',sizeof(str));
clrscr();
stop_flash = 1;
strcpy(change,"play song from ");
gotoxy(1,25);
printf("MP3 Pro v 2.0 copyright (C) 2002.Press Esc to exit.");
gotoxy(1,2);
printf("Enter value for position: ");
i = 0;
while(1) {
for (;;) {
err = mciSendString("status song mode",Stat,128,0);
if (err > 0) {
perror("error");
exit(1);
}
StatSong();
if (!isPlay) Usage();
if (kbhit()) break;
}
ch = getch();
if (ch == 27) {
stop_flash = 0;
Usage();
}
if (ch == 13) {
if (i == 0) continue;
break;
}
if (ch == 8) {
str[i] = '\0';
i--;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -