qfedu-c-level/lyric_analysis/srcs/main.c

53 lines
1.6 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "./includes/lrc.h"
#include "./includes/console.h"
#include "./includes/start_mplayer.h"
#include "includes/time_delay.h"
int main()
{
// 定义歌曲和歌词文件路径
const char *song_path = "./songs/简单爱.mp3";
const char *lrc_path = "./lrcs/简单爱.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; // 为歌词数据分配内存失败,退出程序
}
// 读入歌词内容
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); // 关闭歌词文件
return 0;
}