百问网视频教程: https://www.bilibili.com/video/BV1Ya411r7K2
视频提及的 codeblocks-20.03mingw-setup 下载地址: https://www.codeblocks.org/downloads/binaries/
离线
添加触摸声音:
lvgl/src/core/lv_obj.c
static void lv_obj_event(const lv_obj_class_t * class_p, lv_event_t * e)
{
LV_UNUSED(class_p);
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * obj = lv_event_get_current_target(e);
if(code == LV_EVENT_PRESSED) {
lv_obj_add_state(obj, LV_STATE_PRESSED);
//这里添加触摸声音输出
}
else if(code == LV_EVENT_RELEASED)
...
离线
linux 终端列出目录下所有.mp4文件:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h> // POSIX 目录遍历库
// 存储文件名的结构体
typedef struct {
char *filename;
} FileEntry;
// 全局文件列表
FileEntry *file_list = NULL;
int file_count = 0;
// 扩展名匹配
int is_media_file(const char *filename) {
const char *ext = strrchr(filename, '.');
if (!ext) return 0;
return (strcmp(ext, ".mp3") == 0 || strcmp(ext, ".mp4") == 0);
}
// 递归查找媒体文件
void find_media_files(const char *path) {
DIR *dir = opendir(path);
if (!dir) {
fprintf(stderr, "无法打开目录: %s\n", path);
return;
}
struct dirent *entry;
while ((entry = readdir(dir)) != NULL) {
// 跳过当前目录和父目录
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
continue;
// 构造完整路径
char full_path[256];
snprintf(full_path, sizeof(full_path), "%s/%s", path, entry->d_name);
// 如果是目录,则递归处理
if (entry->d_type == DT_DIR) {
find_media_files(full_path);
} else if (is_media_file(entry->d_name)) {
// 分配内存并保存文件名
file_list = realloc(file_list, (file_count + 1) * sizeof(FileEntry));
file_list[file_count].filename = strdup(entry->d_name);
file_count++;
}
}
closedir(dir);
}
void display_file_list() {
for (int i = 0; i < file_count; i++) {
printf("%s\n", file_list[i].filename);
}
}
int main() {
// 查找文件
find_media_files("/mnt/hgfs/D/1122/"); // 注意使用正斜杠路径
// 显示文件列表
display_file_list();
// 清理资源
for (int i = 0; i < file_count; i++) {
free(file_list[i].filename);
}
free(file_list);
return 0;
}
离线