From 4cd18875717454de1fc3e000c876d4d6eb9ff146 Mon Sep 17 00:00:00 2001 From: cheng Date: Sat, 13 Sep 2025 18:33:38 +0800 Subject: [PATCH] =?utf8?q?=E5=AE=9E=E7=8E=B0=E6=95=85=E4=BA=8B=E7=9A=84?= =?utf8?q?=EF=BC=9A=E6=92=AD=E5=8F=91=E6=8C=87=E5=AE=9A=E6=96=87=E4=BB=B6?= =?utf8?q?=EF=BC=8C=E6=9A=82=E5=81=9C=E6=92=AD=E6=94=BE=EF=BC=8C=E6=81=A2?= =?utf8?q?=E5=A4=8D=E6=92=AD=E6=94=BE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../leiniao/include/ln_story_player_simple.h | 40 ++++++ .../leiniao/src/ln_story_player_simple.cpp | 114 ++++++++++++++++++ .../zhihui/leiniao/imsl_ln/leiniao_api_at.c | 41 ++++++- code/sdk/zhihui/leiniao/imsl_ln/ln_api.c | 51 ++++++++ code/sdk/zhihui/leiniao/imsl_ln/ln_api.h | 3 + 5 files changed, 248 insertions(+), 1 deletion(-) diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/leiniao/include/ln_story_player_simple.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/leiniao/include/ln_story_player_simple.h index b558268c9..e5ba5d8d5 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/leiniao/include/ln_story_player_simple.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/leiniao/include/ln_story_player_simple.h @@ -56,6 +56,46 @@ int ln_story_player_simple_get_current_index(void); */ int ln_story_player_simple_get_file_count(void); +/** + * @brief 播放指定音频文件 + * @param file_path 音频文件完整路径 + * @return true 成功,false 失败 + * + * 功能说明: + * - 播放指定的单个音频文件 + * - 不会自动播放下一个文件 + * - 需要手动调用停止或暂停 + */ +bool ln_story_player_simple_play_file(const char *file_path); + +/** + * @brief 暂停播放 + * @return true 成功,false 失败 + * + * 功能说明: + * - 暂停当前正在播放的音频 + * - 保持播放器状态,可以恢复播放 + * - 不会清理音频资源 + */ +bool ln_story_player_simple_pause(void); + +/** + * @brief 恢复播放 + * @return true 成功,false 失败 + * + * 功能说明: + * - 恢复之前暂停的音频播放 + * - 只能在暂停状态下调用 + * - 如果当前没有暂停的音频,返回失败 + */ +bool ln_story_player_simple_resume(void); + +/** + * @brief 检查是否暂停 + * @return true 已暂停,false 未暂停 + */ +bool ln_story_player_simple_is_paused(void); + /** * @brief 处理播放器消息队列命令(内部使用) * @param cmd 命令类型 diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/leiniao/src/ln_story_player_simple.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/leiniao/src/ln_story_player_simple.cpp index d8ffe7d2e..441ae6eca 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/leiniao/src/ln_story_player_simple.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/leiniao/src/ln_story_player_simple.cpp @@ -58,6 +58,7 @@ typedef struct /* 状态标志 */ bool is_playing; bool should_stop; + bool is_paused; // 暂停状态标志 } ln_story_player_simple_t; @@ -86,6 +87,7 @@ public: else { printf("[SIMPLE_PLAYER] all files played, stopping(所有文件播放完成)\n"); + do_ln_http_server_send_data(LN_HTTP_SERVICE_CMD_AUDIO_STOP, NULL, 0); impl_->is_playing = false; } } @@ -432,6 +434,7 @@ static bool ln_story_player_simple_player_stat(ln_story_player_simple_t *impl, i } impl->is_playing = true; + impl->is_paused = false; // 重置暂停状态 printf("[SIMPLE_PLAYER] started playing file %d\n", file_index); return true; } @@ -530,6 +533,7 @@ void ln_story_player_simple_stop(void) g_simple_player.should_stop = true; g_simple_player.is_playing = false; + g_simple_player.is_paused = false; if (!g_simple_player.player) { @@ -610,6 +614,116 @@ int ln_story_player_simple_get_file_count(void) return g_simple_player.file_count; } +// 播放指定音频文件 +bool ln_story_player_simple_play_file(const char *file_path) +{ + if (!file_path) + { + printf("[SIMPLE_PLAYER] invalid file path\n"); + return false; + } + + printf("[SIMPLE_PLAYER] playing single file: %s\n", file_path); + + // 如果已经在播放,先停止 + if (g_simple_player.is_playing) + { + printf("[SIMPLE_PLAYER] stopping current playback\n"); + ln_story_player_simple_stop(); + } + + // 初始化音频(只初始化一次) + if (!AudioInit()) + { + printf("[SIMPLE_PLAYER] audio init failed\n"); + return false; + } + + // 设置单个文件播放模式 + g_simple_player.file_count = 1; + g_simple_player.current_index = 0; + g_simple_player.should_stop = false; + g_simple_player.is_paused = false; + strncpy(g_simple_player.file_paths[0], file_path, sizeof(g_simple_player.file_paths[0]) - 1); + g_simple_player.file_paths[0][sizeof(g_simple_player.file_paths[0]) - 1] = '\0'; + + // 播放文件 + if (!ln_story_player_simple_play_file(&g_simple_player, 0)) + { + printf("[SIMPLE_PLAYER] failed to start playing single file\n"); + return false; + } + + printf("[SIMPLE_PLAYER] single file playback started successfully\n"); + return true; +} + +// 暂停播放 +bool ln_story_player_simple_pause(void) +{ + if (!g_simple_player.player) + { + printf("[SIMPLE_PLAYER] player not initialized\n"); + return false; + } + + if (!g_simple_player.is_playing) + { + printf("[SIMPLE_PLAYER] not currently playing\n"); + return false; + } + + if (g_simple_player.is_paused) + { + printf("[SIMPLE_PLAYER] already paused\n"); + return false; + } + + int32_t ret = g_simple_player.player->Pause(); + if (ret != 0) + { + printf("[SIMPLE_PLAYER] pause failed: %d\n", ret); + return false; + } + + g_simple_player.is_paused = true; + printf("[SIMPLE_PLAYER] playback paused\n"); + return true; +} + +// 恢复播放 +bool ln_story_player_simple_resume(void) +{ + if (!g_simple_player.player) + { + printf("[SIMPLE_PLAYER] player not initialized\n"); + return false; + } + + if (!g_simple_player.is_paused) + { + printf("[SIMPLE_PLAYER] not currently paused\n"); + return false; + } + + int32_t ret = g_simple_player.player->Play(); + if (ret != 0) + { + printf("[SIMPLE_PLAYER] resume failed: %d\n", ret); + return false; + } + + g_simple_player.is_paused = false; + printf("[SIMPLE_PLAYER] playback resumed\n"); + return true; +} + +// 检查是否暂停 +bool ln_story_player_simple_is_paused(void) +{ + return g_simple_player.is_paused; +} + #ifdef __cplusplus #if __cplusplus } diff --git a/code/sdk/zhihui/leiniao/imsl_ln/leiniao_api_at.c b/code/sdk/zhihui/leiniao/imsl_ln/leiniao_api_at.c index 0ca99aa5c..7b48c9759 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/leiniao_api_at.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/leiniao_api_at.c @@ -645,7 +645,7 @@ static uint32_t ln_audio_play_at(uint8_t *para, uint32_t paraLen, char *strCommo return ERRCODE_SUCC; } -/* 音频停止: AT^LN_STORY_PLAY_PREV */ +/* 音频停止: AT^LN_STORY_STOP_AT */ static uint32_t ln_audio_stop_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd) { VAD_UNUSED(para); VAD_UNUSED(paraLen); VAD_UNUSED(strCommonCmd); @@ -654,6 +654,42 @@ static uint32_t ln_audio_stop_at(uint8_t *para, uint32_t paraLen, char *strCommo return ERRCODE_SUCC; } +/* 播放指定文件: AT^LN_AUDIO_PLAY_FILE=file_path */ +static uint32_t ln_audio_play_file_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + VAD_UNUSED(strCommonCmd); + printf("[LN][AUDIO_PLAY_FILE]\n"); + if (para && paraLen > 0) + { + // 将参数作为文件路径发送 + do_ln_http_server_send_data(LN_HTTP_SERVICE_CMD_AUDIO_PLAY_FILE, (char*)para, paraLen); + } + else + { + printf("[LN] Error: No file path provided\n"); + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} + +/* 暂停播放: AT^LN_AUDIO_PAUSE */ +static uint32_t ln_audio_pause_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + VAD_UNUSED(para); VAD_UNUSED(paraLen); VAD_UNUSED(strCommonCmd); + printf("[LN][AUDIO_PAUSE]\n"); + do_ln_http_server_send_data(LN_HTTP_SERVICE_CMD_AUDIO_PAUSE, NULL, 0); + return ERRCODE_SUCC; +} + +/* 恢复播放: AT^LN_AUDIO_RESUME */ +static uint32_t ln_audio_resume_at(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + VAD_UNUSED(para); VAD_UNUSED(paraLen); VAD_UNUSED(strCommonCmd); + printf("[LN][AUDIO_RESUME]\n"); + do_ln_http_server_send_data(LN_HTTP_SERVICE_CMD_AUDIO_RESUME, NULL, 0); + return ERRCODE_SUCC; +} + static const at_cmd_table_t g_ln_api_cmd[] = { /* ----------------------------------- VAD ---------------------------------- */ @@ -681,6 +717,9 @@ static const at_cmd_table_t g_ln_api_cmd[] = { /* 音频播放 */ {(char *)"AT^LN_STORY_PLAY_AT", ln_audio_play_at, (char *)"播放音频: AT^LN_STORY_PLAY_AT"}, {(char *)"AT^LN_STORY_STOP_AT", ln_audio_stop_at, (char *)"停止播放音频: AT^LN_STORY_STOP_AT"}, + {(char *)"AT^LN_AUDIO_PLAY_FILE", ln_audio_play_file_at, (char *)"播放指定文件: AT^LN_AUDIO_PLAY_FILE=/path/to/file.mp3"}, + {(char *)"AT^LN_AUDIO_PAUSE", ln_audio_pause_at, (char *)"暂停播放: AT^LN_AUDIO_PAUSE"}, + {(char *)"AT^LN_AUDIO_RESUME", ln_audio_resume_at, (char *)"恢复播放: AT^LN_AUDIO_RESUME"}, }; at_cmd_table_t *get_leiniao_api_cmd_table(uint32_t *cmd_count) diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api.c index 0f1d47ae4..bcb0a6f55 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api.c @@ -472,6 +472,57 @@ static void ln_http_server_send_task(void const *arg) ln_story_player_simple_handle_message(LN_HTTP_SERVICE_CMD_AUDIO_PLAY_NEXT, NULL, 0); #endif } + else if (mail.cmd == LN_HTTP_SERVICE_CMD_AUDIO_PLAY_FILE) + { + printf("LN_HTTP_SERVICE_CMD_AUDIO_PLAY_FILE:播放指定文件\n"); + #ifdef BOARD_N9 + if (mail.data != NULL) + { + char *file_path = (char*)mail.data; + printf("Playing file: %s\n", file_path); + if (ln_story_player_simple_play_file(file_path)) + { + printf("File playback started successfully\n"); + } + else + { + printf("Failed to start file playback\n"); + } + } + else + { + printf("Error: No file path provided\n"); + } + #endif + } + else if (mail.cmd == LN_HTTP_SERVICE_CMD_AUDIO_PAUSE) + { + printf("LN_HTTP_SERVICE_CMD_AUDIO_PAUSE:暂停播放\n"); + #ifdef BOARD_N9 + if (ln_story_player_simple_pause()) + { + printf("Playback paused successfully\n"); + } + else + { + printf("Failed to pause playback\n"); + } + #endif + } + else if (mail.cmd == LN_HTTP_SERVICE_CMD_AUDIO_RESUME) + { + printf("LN_HTTP_SERVICE_CMD_AUDIO_RESUME:恢复播放\n"); + #ifdef BOARD_N9 + if (ln_story_player_simple_resume()) + { + printf("Playback resumed successfully\n"); + } + else + { + printf("Failed to resume playback\n"); + } + #endif + } if (mail.data != NULL) { printf("free(mail.data)\n"); diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api.h b/code/sdk/zhihui/leiniao/imsl_ln/ln_api.h index 982a3c33a..6bde4a0bd 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api.h +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api.h @@ -81,6 +81,9 @@ typedef struct #define LN_HTTP_SERVICE_CMD_AUDIO_PLAY 0x1001 /* 播放音频 */ #define LN_HTTP_SERVICE_CMD_AUDIO_STOP 0x1002 /* 停止播放音频 */ #define LN_HTTP_SERVICE_CMD_AUDIO_PLAY_NEXT 0x1003 /* 播放下一首 */ +#define LN_HTTP_SERVICE_CMD_AUDIO_PLAY_FILE 0x1004 /* 播放指定文件 */ +#define LN_HTTP_SERVICE_CMD_AUDIO_PAUSE 0x1005 /* 暂停播放 */ +#define LN_HTTP_SERVICE_CMD_AUDIO_RESUME 0x1006 /* 恢复播放 */ typedef struct { -- 2.17.1