2023-07-22 10:34:16 +08:00
|
|
|
|
#include "./includes/lrc.h"
|
|
|
|
|
#include "./includes/console.h"
|
|
|
|
|
#include "./includes/start_mplayer.h"
|
2023-07-22 15:15:41 +08:00
|
|
|
|
#include "includes/time_delay.h"
|
2023-07-22 10:34:16 +08:00
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
// 定义歌曲和歌词文件路径
|
|
|
|
|
const char *song_path = "../songs/简单爱.mp3";
|
|
|
|
|
const char *lrc_path = "../lrc/简单爱.lrc";
|
|
|
|
|
|
|
|
|
|
FILE *fp = open_lrc_file(lrc_path); // 打开歌词文件
|
|
|
|
|
if (NULL == fp)
|
|
|
|
|
{
|
|
|
|
|
printf("歌词打开失败\n");
|
|
|
|
|
perror("fopen");
|
|
|
|
|
return -1; // 打开歌词文件失败,退出程序
|
|
|
|
|
}
|
|
|
|
|
mplayer_play(song_path); // 启动mplayer播放器,播放歌曲
|
|
|
|
|
|
|
|
|
|
long lrc_size = get_lrc_size(fp); // 获取并打印歌词文件大小
|
|
|
|
|
|
|
|
|
|
char *lrc_mem_data = (char *)malloc(lrc_size); // 为歌词数据分配内存
|
|
|
|
|
if (NULL == lrc_mem_data)
|
|
|
|
|
{
|
|
|
|
|
printf("歌词数据分配内存失败\n");
|
|
|
|
|
perror("malloc");
|
|
|
|
|
return -1; // 为歌词数据分配内存失败,退出程序
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-22 15:15:41 +08:00
|
|
|
|
// 读入歌词内容
|
|
|
|
|
fread(lrc_mem_data, lrc_size, 1, fp); // 读入歌词数据
|
|
|
|
|
// printf("%s", lrc_mem_data);
|
|
|
|
|
// FILE *fwx = fopen("../lrc/简单爱copy.lrc", "w");
|
|
|
|
|
// fwrite(lrc_mem_data, lrc_size, 1, fwx);
|
|
|
|
|
|
|
|
|
|
// 逐行解析歌词
|
|
|
|
|
char *line = strtok(lrc_mem_data, "\r\n"); // 逐行解析歌词
|
|
|
|
|
int i = 1;
|
|
|
|
|
while (line != NULL)
|
|
|
|
|
{
|
|
|
|
|
time_delay(2);
|
|
|
|
|
printf("%d.\t%s\n", i++, line);
|
|
|
|
|
line = strtok(NULL, "\r\n");
|
|
|
|
|
}
|
|
|
|
|
// FILE *fwx = fopen("../lrc/简单爱copy.lrc", "wb");
|
|
|
|
|
// fwrite(lrc_mem_data, lrc_size, 1, fwx);
|
|
|
|
|
|
|
|
|
|
// 释放内存,关闭文件
|
|
|
|
|
free(lrc_mem_data); // 释放歌词数据内存
|
|
|
|
|
fclose(fp); // 关闭歌词文件
|
2023-07-22 10:34:16 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|