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()
|
|
|
|
|
{
|
|
|
|
|
// 定义歌曲和歌词文件路径
|
2023-07-22 15:40:53 +08:00
|
|
|
|
const char *song_path = "./songs/简单爱.mp3";
|
|
|
|
|
const char *lrc_path = "./lrcs/简单爱.lrc";
|
2023-07-22 10:34:16 +08:00
|
|
|
|
|
2023-07-23 17:30:05 +08:00
|
|
|
|
FILE *lrc_fp = open_lrc_file(lrc_path); // 打开歌词文件
|
2023-07-23 17:52:02 +08:00
|
|
|
|
long lrc_size = get_lrc_size(lrc_fp); // 获取并打印歌词文件大小
|
2023-07-23 17:30:05 +08:00
|
|
|
|
// printf("歌词大小为: %ld Byte\n", lrc_size);
|
|
|
|
|
char *lrc_mem_data = get_lrc_mem_data(lrc_fp); // 获取歌词数据
|
|
|
|
|
|
|
|
|
|
// 逐行解析歌词
|
|
|
|
|
char *lrc_lines[200] = {NULL}; // 定义歌词行指针数组
|
|
|
|
|
int i = 0; // 定义歌词行数
|
|
|
|
|
lrc_lines[i] = strtok(lrc_mem_data, "\r\n"); // 将歌词数据按行分割
|
|
|
|
|
while (lrc_lines[i] != NULL)
|
2023-07-22 10:34:16 +08:00
|
|
|
|
{
|
2023-07-23 17:30:05 +08:00
|
|
|
|
// 打印歌词
|
|
|
|
|
// time_delay(1); // 延时1秒
|
|
|
|
|
// printf("%d.\t%s\n", i, lrc_lines[i]); // 打印歌词
|
|
|
|
|
i++; // 行数加1
|
|
|
|
|
lrc_lines[i] = strtok(NULL, "\r\n"); // 将剩余行歌词数据按行分割
|
2023-07-22 10:34:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-23 17:30:05 +08:00
|
|
|
|
int rows = i; // 获取歌词总行数
|
2023-07-22 10:34:16 +08:00
|
|
|
|
|
2023-07-23 17:52:02 +08:00
|
|
|
|
handle_first_4_lines(lrc_lines); // 处理前 4 行歌词
|
2023-07-22 15:15:41 +08:00
|
|
|
|
|
2023-07-23 17:52:02 +08:00
|
|
|
|
// 保存歌词信息到链表
|
|
|
|
|
LRC *head = NULL; // 定义链表头指针
|
|
|
|
|
head = save_to_linklist(lrc_lines, rows); // 保存到链表s
|
2023-07-23 17:30:05 +08:00
|
|
|
|
|
|
|
|
|
// 开始播放歌曲
|
|
|
|
|
mplayer_play(song_path); // 启动mplayer播放器,播放歌曲
|
2023-07-23 17:52:02 +08:00
|
|
|
|
// 逐行显示歌词
|
|
|
|
|
show_lrcs(head); // 显示歌词
|
2023-07-22 15:15:41 +08:00
|
|
|
|
|
|
|
|
|
// 释放内存,关闭文件
|
|
|
|
|
free(lrc_mem_data); // 释放歌词数据内存
|
2023-07-23 17:52:02 +08:00
|
|
|
|
free(head); // 释放链表内存
|
|
|
|
|
fclose(lrc_fp); // 关闭歌词文件
|
2023-07-22 10:34:16 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|