From 6e0ec2246e7aea3203637688afae5527bde85f67 Mon Sep 17 00:00:00 2001 From: penglei <1624952103@qq.com> Date: Tue, 16 Sep 2025 19:03:14 +0800 Subject: [PATCH] =?utf8?q?=E9=9B=B7=E9=B8=9F=E4=BC=98=E5=8C=96=E9=A9=AC?= =?utf8?q?=E8=BE=BE=E6=8E=A7=E5=88=B6=EF=BC=8C=E8=83=8C=E5=85=89=E6=8E=A7?= =?utf8?q?=E5=88=B6=EF=BC=8C=E5=BC=80=E6=9C=BA=E5=A2=9E=E5=8A=A0=E9=9F=B3?= =?utf8?q?=E9=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../power_manager/src/power_display_service.c | 10 ++ .../config/target_config/brandy/config.py | 2 +- .../leiniao/fs/user/music/PowerOn.mp3 | Bin 0 -> 5328 bytes .../brandy_evb/board_config/board_leiniao.h | 25 +-- .../player/interfaces/kits/player.h | 168 +++++++++--------- .../vibrator/service/vibrator_service.cpp | 8 +- code/sdk/zhihui/drivers/vibrator/vibrator.c | 13 +- code/sdk/zhihui/drivers/vibrator/vibrator.h | 4 + .../zhihui/drivers/vibrator/vibrator_at_cmd.c | 6 +- code/sdk/zhihui/utils/custom_utils.c | 9 +- code/sdk/zhihui/utilscpp/CMakeLists.txt | 3 + code/sdk/zhihui/utilscpp/custom_utilscpp.cpp | 123 +++++++++++++ code/sdk/zhihui/utilscpp/custom_utilscpp.h | 5 +- 13 files changed, 270 insertions(+), 106 deletions(-) create mode 100644 code/sdk/build/config/target_config/brandy/mk_fs_image/leiniao/fs/user/music/PowerOn.mp3 diff --git a/code/sdk/application/wearable/ln/service/power_manager/src/power_display_service.c b/code/sdk/application/wearable/ln/service/power_manager/src/power_display_service.c index 297dd3a53..f9f4cbdee 100644 --- a/code/sdk/application/wearable/ln/service/power_manager/src/power_display_service.c +++ b/code/sdk/application/wearable/ln/service/power_manager/src/power_display_service.c @@ -24,6 +24,10 @@ #include "graphic_service_wrapper.h" #endif +#ifdef CUSTOM_UTILS +#include "custom_utils.h" +#endif + #define DISPLAY_AUTO_POWER_OFF_PERIOD_MS 5000 #define DISPLAY_DEFAULT_BRIGHTNESS 50 #define POWER_DISPLAY_QUEUE_MAX_SIZE 64 @@ -90,6 +94,9 @@ static errcode_t power_display_msg_write(uint32_t msg_id, uint8_t *msg, uint16_t static errcode_t power_display_turn_on_screen(void) { +#if defined(CUSTOM_UTILS) && defined(BOARD_LEINIAO) + uapi_lcd_backlight_on(50); +#endif #ifndef SUPPORT_OHOSFWK message_type_t mt = TURN_ON_SCREEN_CMD; uint32_t event_info = 0; @@ -105,6 +112,9 @@ static errcode_t power_display_turn_on_screen(void) static errcode_t power_display_turn_off_screen(void) { +#if defined(CUSTOM_UTILS) && defined(BOARD_LEINIAO) + uapi_lcd_backlight_off(); +#endif #ifndef SUPPORT_OHOSFWK message_type_t mt = TURN_OFF_SCREEN_CMD; uint32_t event_info = 0; diff --git a/code/sdk/build/config/target_config/brandy/config.py b/code/sdk/build/config/target_config/brandy/config.py index d98a52c00..176043ccc 100644 --- a/code/sdk/build/config/target_config/brandy/config.py +++ b/code/sdk/build/config/target_config/brandy/config.py @@ -1225,7 +1225,7 @@ target = { # 'WEARABLE_LOG_DEBUG', 'SUPPORT_RC_CALIBRATION', # 'PPG_HX3695', - 'VIB_USE_PWM', + # 'VIB_USE_PWM', 'CONFIG_PWM_SUPPORT', # 'ACC_LIS2DOC', 'ENABLE_CUSTOM_I2C', diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/leiniao/fs/user/music/PowerOn.mp3 b/code/sdk/build/config/target_config/brandy/mk_fs_image/leiniao/fs/user/music/PowerOn.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..b1488e205156d46e2db758c2a07b8d0a4aeb1eb9 GIT binary patch literal 5328 zcmeI#S5y<*zrgW8AVTO>N+5v2gA}DnIrJigYCs}Y0qH2HAkqmm`F$)SHvv`U;5l(``cn{R{i&ebWzQ1^>j(4>FSb<*}J2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tnm2K32lKa|Y`|PxNHAL3Wom)v+_+#nA z5D0b{Z$sQaara#6&F|K0oVf_+-b`O33SLP~GDX+u#3jzenNX9jOATWm#-7DWTPPwe!KA zJ5p@Y(~W6Wb`RICx+J+28c`&VHgn$1(>`wawE0zaeoH;D!t!)UfkL^sY;uk$An&&} zJayo}nQnAL!3VWM%SG(fk3y8~%^Xg!p9dI1!cQfnM`zEGIY5G|?DBfijvY+&av={V zEIJ75qbPmJvz$%H2A%@y)99~&fE8|W`;j&cQ*t6DezH>H0SIfgdndM z`sHrO93Cx{OLGq6HhpVloG!t^Zi~boI{rCR^wON=<+9soKLQTSCIS(iM0*nM_c<@L zYFGtMx)QvZxYj5Pz;Mm!d(cOylTdfg8D8!IXq(ROUTQ_TEaAg|<(1x6T|&zy+NQ`g zP?RLWoy+npN!x9Sx=2_XnI~swLAy{7Qu83vH;#$1vS=OEP*+F)-(4&ZpiqGO%I=%7 z{J)R=PdNU0W0oi3pZ~$%o`16Zy8rI;E5*MKzx(`amS3B{`}|7rufy*?|C;63=KqI2 Kzp(#-;lBX0 indicates no sound, and 100 - * indicates the original volume. - * - * @param leftVolume Indicates the target volume of the left audio channel to set, ranging from 0 to 300. - * @param rightVolume Indicates the target volume of the right audio channel to set, ranging from 0 to 300. + * @brief Sets the volume of the player. + * + * This function can be used during playback or pause. The value 0 indicates no sound, and 100 + * indicates the original volume. + * + * @param leftVolume Indicates the target volume of the left audio channel to set, ranging from 0 to 300. + * @param rightVolume Indicates the target volume of the right audio channel to set, ranging from 0 to 300. * @return Returns 0 if the setting is successful; returns -1 otherwise. * @since 1.0 * @version 1.0 @@ -316,22 +316,22 @@ public: * @return Returns true if the player is looping; returns false otherwise. * @since 1.0 * @version 1.0 - */ - bool IsSingleLooping(); - - /** - * @brief Obtains the player state. - * - * @param state Indicates the player state. For details, see {@link PlayerStates}. - * @return Returns 0 if the player state is obtained; returns -1 otherwise. - * @since 1.0 - * @version 1.0 - */ - int32_t GetPlayerState(int32_t &state) const; - - /** - * @brief Obtains the playback position, accurate to millisecond. - * + */ + bool IsSingleLooping(); + + /** + * @brief Obtains the player state. + * + * @param state Indicates the player state. For details, see {@link PlayerStates}. + * @return Returns 0 if the player state is obtained; returns -1 otherwise. + * @since 1.0 + * @version 1.0 + */ + int32_t GetPlayerState(int32_t &state) const; + + /** + * @brief Obtains the playback position, accurate to millisecond. + * * @param time Indicates the playback position. * @return Returns 0 if the playback position is obtained; returns -1 otherwise. * @since 1.0 @@ -352,38 +352,38 @@ public: * @version 1.0 */ int32_t GetDuration(int64_t &durationMs) const; - - /** - * Sets the playback speed. - * - * @param speed Indicates the playback speed to set, which support {-128/-64/-32/-16/-8/-4/-2/1/2/4/8/16/32/64/128} - * @return Returns {@code 0} if the playback speed is set; returns {@code -1} otherwise. - */ - int32_t SetPlaybackSpeed(float speed); - /** - * Obtains the playback speed. - * - * @param speed Indicates the playback speed. - * @return Returns {@code 0} if the playback speed is set; returns {@code -1} otherwise. - */ - int32_t GetPlaybackSpeed(float &speed); - /** - * Sets the audio type. - * - * @param type Indicates the audio type. - * @return Returns {@code 0} if the setting is successful; returns {@code -1} otherwise. - */ - int32_t SetAudioStreamType(int32_t type); - /** - * Obtains the audio type. - * - * @param type Indicates the audio type. - * @return Returns {@code 0} if the playback speed is set; returns {@code -1} otherwise. - */ - int32_t GetAudioStreamType(int32_t &type); - /** - * @brief Restores the player to the initial state. - * + + /** + * Sets the playback speed. + * + * @param speed Indicates the playback speed to set, which support {-128/-64/-32/-16/-8/-4/-2/1/2/4/8/16/32/64/128} + * @return Returns {@code 0} if the playback speed is set; returns {@code -1} otherwise. + */ + int32_t SetPlaybackSpeed(float speed); + /** + * Obtains the playback speed. + * + * @param speed Indicates the playback speed. + * @return Returns {@code 0} if the playback speed is set; returns {@code -1} otherwise. + */ + int32_t GetPlaybackSpeed(float &speed); + /** + * Sets the audio type. + * + * @param type Indicates the audio type. + * @return Returns {@code 0} if the setting is successful; returns {@code -1} otherwise. + */ + int32_t SetAudioStreamType(int32_t type); + /** + * Obtains the audio type. + * + * @param type Indicates the audio type. + * @return Returns {@code 0} if the playback speed is set; returns {@code -1} otherwise. + */ + int32_t GetAudioStreamType(int32_t &type); + /** + * @brief Restores the player to the initial state. + * * @return Returns 0 if the player is restored; returns -1 otherwise. * @since 1.0 * @version 1.0 @@ -404,18 +404,18 @@ public: * * @param cb Indicates the listener to register. For details, see {@link PlayerCallback}. * @since 1.0 - * @version 1.0 - */ - void SetPlayerCallback(const std::shared_ptr &cb); - /** - * set parameter through format, extended interface. - * - * @param params Indicates the extended-informations. Format see {@link Format} - * @return Returns {@code 0} if set parameter successfully; returns {@code -1} otherwise. - * @note not support on current version - */ - int32_t SetParameter(const Format ¶ms); - /** + * @version 1.0 + */ + void SetPlayerCallback(const std::shared_ptr &cb); + /** + * set parameter through format, extended interface. + * + * @param params Indicates the extended-informations. Format see {@link Format} + * @return Returns {@code 0} if set parameter successfully; returns {@code -1} otherwise. + * @note not support on current version + */ + int32_t SetParameter(const Format ¶ms); + /** * get parameter through format, extended interface. * * @param params Indicates the extended-informations. Format see {@link Format} @@ -423,44 +423,44 @@ public: */ int32_t GetParameter(Format ¶ms); /** - * get the total number of the tracks. - * - * @param totalTracks Indicates the total number of the tracks. - * @return Returns {@code 0} if set parameter successfully; returns {@code -1} otherwise. - */ + * get the total number of the tracks. + * + * @param totalTracks Indicates the total number of the tracks. + * @return Returns {@code 0} if set parameter successfully; returns {@code -1} otherwise. + */ int32_t GetTotalTracks(int32_t &totalTracks); /** * set audio sessionid. - * + * * @param sessionId indicates sessionid to be set. * @return Returns {@code 0} if set parameter successfully; returns {@code -1} otherwise. */ int32_t SetAudioSessionId(uint32_t sessionId); /** * get current audio sessionid. - * + * * @param indicates sessionid. * @return Returns {@code 0} if get parameter successfully; returns {@code -1} otherwise. */ int32_t GetAudioSessionId(uint32_t &sessionId); /** * set output device. - * + * * @param deviceId indicates device to be set. * @return Returns {@code 0} if set parameter successfully; returns {@code -1} otherwise. */ int32_t SetOutputDevice(int32_t deviceId); /** * get current route device. - * + * * @param deviceId indicates the output device. * @return Returns {@code 0} if get parameter successfully; returns {@code -1} otherwise. */ int32_t GetRoutedDeviceId(int32_t &deviceId); int32_t DumpInfo(PlayerDebugInfo *playerInfo); -private: - class PlayerImpl; +private: + class PlayerImpl; std::unique_ptr impl_; }; } // namespace Media diff --git a/code/sdk/zhihui/drivers/vibrator/service/vibrator_service.cpp b/code/sdk/zhihui/drivers/vibrator/service/vibrator_service.cpp index 4ee1aee83..1a37565ba 100644 --- a/code/sdk/zhihui/drivers/vibrator/service/vibrator_service.cpp +++ b/code/sdk/zhihui/drivers/vibrator/service/vibrator_service.cpp @@ -2,7 +2,7 @@ * @Author: penglei 1624952103@qq.com * @Date: 2024-08-08 16:33:23 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2025-07-31 17:09:45 + * @LastEditTime: 2025-09-16 15:56:41 * @FilePath: /FD230/code/sdk/drivers/peripheral/vibrator/service/vibrator_service.cpp * @Description: * @@ -61,17 +61,17 @@ void custom_VibratorFunc_int(int vibratorType) case 3: mail.cycle_time_ms = 235; mail.duty = 50; - mail.duration_time_ms = 60; + mail.duration_time_ms = 600; break; case 2: mail.cycle_time_ms = 235; mail.duty = 50; - mail.duration_time_ms = 40; + mail.duration_time_ms = 400; break; case 1: mail.cycle_time_ms = 235; mail.duty = 50; - mail.duration_time_ms = 20; + mail.duration_time_ms = 200; break; default: break; diff --git a/code/sdk/zhihui/drivers/vibrator/vibrator.c b/code/sdk/zhihui/drivers/vibrator/vibrator.c index ea6965b77..fe98004e0 100644 --- a/code/sdk/zhihui/drivers/vibrator/vibrator.c +++ b/code/sdk/zhihui/drivers/vibrator/vibrator.c @@ -19,12 +19,17 @@ #include "chip_core_irq.h" #include "pwm.h" #include "pwm_porting.h" -#include "pinctrl.h" #include "vibrator.h" +#ifdef BOARD_LEINIAO +#define VIBRATOR_GPIOPPIN S_HGPIO4 +#else +#define VIBRATOR_GPIOPPIN S_AGPIO_R2 +#endif + // #define VIB_DEBUG #ifdef VIB_USE_PWM -#define VIBRATOR_GPIOPPIN S_AGPIO_R2 + // #define VIBRATORPIN_MODE HAL_PIO_FUNC_PWMP1_M2 #define VIBRATORPIN_MODE HAL_PIO_FUNC_PWMN1_M3 @@ -188,7 +193,7 @@ void g_VibratorFunc(uint16_t duty , uint16_t cycle_time_ms,uint16_t duration_tim } #else -#define VIBRATOR_GPIOPPIN S_AGPIO_R2 + #define VIBRATORPIN_MODE HAL_PIO_FUNC_GPIO static pin_t pin = VIBRATOR_GPIOPPIN; static pin_mode_t mode = VIBRATORPIN_MODE; @@ -221,7 +226,7 @@ void g_VibratorFunc(uint16_t duty , uint16_t cycle_time_ms,uint16_t duration_tim if (delaytime_ms_low == 0) delaytime_ms_low = 1; if (delaytime_ms_high == 0) delaytime_ms_high = 1; - // PRINT("g_VibratorFunc delaytime_ms_high %u , delaytime_ms_low %u \r\n",delaytime_ms_high,delaytime_ms_low ); + printf("fac:g_VibratorFunc delaytime_ms_high %u , delaytime_ms_low %u \r\n",delaytime_ms_high,delaytime_ms_low ); while(duration_time_ms) { diff --git a/code/sdk/zhihui/drivers/vibrator/vibrator.h b/code/sdk/zhihui/drivers/vibrator/vibrator.h index 079391598..84c4230fd 100644 --- a/code/sdk/zhihui/drivers/vibrator/vibrator.h +++ b/code/sdk/zhihui/drivers/vibrator/vibrator.h @@ -25,6 +25,10 @@ extern "C" { */ void g_VibratorFunc(uint16_t duty , uint16_t cycle_time_ms,uint16_t duration_time_ms); +#ifdef BOARD_LEINIAO +void uapi_motor_test(void); +#endif + /** * @} */ diff --git a/code/sdk/zhihui/drivers/vibrator/vibrator_at_cmd.c b/code/sdk/zhihui/drivers/vibrator/vibrator_at_cmd.c index 6743ef6e0..7b8128e6c 100644 --- a/code/sdk/zhihui/drivers/vibrator/vibrator_at_cmd.c +++ b/code/sdk/zhihui/drivers/vibrator/vibrator_at_cmd.c @@ -68,7 +68,9 @@ static uint32_t vibrator_do_test(uint8_t *para, uint32_t paraLen, char *strCommo PRINT("VIBRATORTEST ATCMD Convert Command Failed\n"); return ERRCODE_FAIL; } - +#ifdef BOARD_LEINIAO + uapi_motor_test(); +#else if (argc != 3) { PRINT("VIBRATORTEST ATCMD Set Parameter Failed argc %d, should be AT^VIBRATORTEST=duration cycle duty \n",argc); return ERRCODE_FAIL; @@ -78,6 +80,8 @@ static uint32_t vibrator_do_test(uint8_t *para, uint32_t paraLen, char *strCommo uint16_t duty = (uint16_t)atoi((char*)argv[2]); PRINT("VIBRATORTEST ATCMD custom_VibratorFunc duration %u,cycle %u,duty %u\n",duration,cycle,duty); hal_custom_VibratorFunc(duty,cycle,duration); +#endif + return ERRCODE_SUCC; } diff --git a/code/sdk/zhihui/utils/custom_utils.c b/code/sdk/zhihui/utils/custom_utils.c index b9c93d7ff..2bd48c791 100644 --- a/code/sdk/zhihui/utils/custom_utils.c +++ b/code/sdk/zhihui/utils/custom_utils.c @@ -584,7 +584,11 @@ void startup_post_init_task(void) struct tm* timeinfo; PRINT("startup_post_init_task !\r\n"); - +#ifdef BOARD_LEINIAO + custom_play_audio("/user/music/PowerOn.mp3",100); + LOS_Msleep(1500); + custom_stop_play_audio(); +#endif #ifdef SUPPORT_CYWEE_SERVICE do_cywee_service_check_msg(CYWEE_SERVICE_CMD_TIME_SYNC,NULL); #endif @@ -4341,6 +4345,9 @@ void uapi_lcd_backlight_off(void) void uapi_lcd_backlight_on(uint8_t brightness) { +#ifdef CUSTOM_ZHIHUI + brightness = cm_getScreenBrightness(); +#endif uint8_t fall_edge_cnt = 0; if (brightness <= 11) fall_edge_cnt = 7; else if (brightness <= 24) fall_edge_cnt = 6; diff --git a/code/sdk/zhihui/utilscpp/CMakeLists.txt b/code/sdk/zhihui/utilscpp/CMakeLists.txt index 99caae410..2c2588472 100644 --- a/code/sdk/zhihui/utilscpp/CMakeLists.txt +++ b/code/sdk/zhihui/utilscpp/CMakeLists.txt @@ -18,7 +18,10 @@ set(PRIVATE_HEADER ${CMAKE_SOURCE_DIR}/middleware/utils/update/inner_include ${CMAKE_SOURCE_DIR}/middleware/services/gui/uikit/proprietary/include ${CMAKE_SOURCE_DIR}/middleware/services/gui/uikit/utils/interfaces/kits + ${CMAKE_SOURCE_DIR}/middleware/services/gui/uikit/surface/interfaces/kits ${CMAKE_SOURCE_DIR}/middleware/services/gui/uikit/utils/interfaces/innerkits + ${CMAKE_SOURCE_DIR}/middleware/services/media/foundation/player/interfaces/kits + ${CMAKE_SOURCE_DIR}/open_source/openharmony/drivers/peripheral/display/interfaces/include ) set(PRIVATE_DEFINES diff --git a/code/sdk/zhihui/utilscpp/custom_utilscpp.cpp b/code/sdk/zhihui/utilscpp/custom_utilscpp.cpp index cae32a96a..48020d931 100644 --- a/code/sdk/zhihui/utilscpp/custom_utilscpp.cpp +++ b/code/sdk/zhihui/utilscpp/custom_utilscpp.cpp @@ -21,6 +21,8 @@ #include "audio_manager.h" #include "audio_base_type.h" +#include "player_lite/js/builtin/include/audio_player.h" + #include "bts_br_gap.h" @@ -444,4 +446,125 @@ void custom_factory_bt_scan_stop(void) #endif #endif +} + +/** + * @brief 播放指定路径的音频文件 + * @param filePath 音频文件路径 + * @param volume 音量 (0-100) + * @return 0: 成功, -1: 失败 + */ +int custom_play_audio(const char* filePath, float volume) +{ + if (!filePath) { + filePath = "/user/userdata/1.mp3"; + } + + printf("=== Starting AudioPlayer playback ===\n"); + printf("File: %s, Volume: %.1f%%\n", filePath, volume); + + // 检查文件是否存在 + struct stat fileStat; + if (stat(filePath, &fileStat) != 0 || !S_ISREG(fileStat.st_mode)) { + printf("ERROR: Audio file not found: %s\n", filePath); + return -1; + } + printf("Audio file exists, size: %ld bytes\n", fileStat.st_size); + + // 获取AudioPlayer单例 + OHOS::ACELite::AudioPlayer* player = OHOS::ACELite::AudioPlayer::GetInstance(); + if (!player) { + printf("ERROR: Failed to get AudioPlayer instance\n"); + return -1; + } + printf("AudioPlayer instance obtained\n"); + + // 检查初始状态 + bool initialPlaying = player->IsPlaying(); + printf("Initial playing state: %s\n", initialPlaying ? "true" : "false"); + + // 先停止当前播放 + if (initialPlaying) { + printf("Stopping current playback...\n"); + bool stopResult = player->Stop(); + printf("Initial stop result: %s\n", stopResult ? "SUCCESS" : "FAILED"); + } + + // 设置音频源 + printf("Setting audio source...\n"); + if (!player->SetSrc(const_cast(filePath), false)) { + printf("ERROR: Failed to set audio source\n"); + return -1; + } + printf("Audio source set successfully\n"); + + // 设置音量 (AudioPlayer的音量范围是0.0-1.0) + double normalizedVolume = volume / 100.0; + if (normalizedVolume > 1.0) normalizedVolume = 1.0; + if (normalizedVolume < 0.0) normalizedVolume = 0.0; + + printf("Setting volume to %.2f (%.1f%%)\n", normalizedVolume, volume); + if (!player->SetVolume(normalizedVolume)) { + printf("WARNING: Failed to set volume, continuing anyway\n"); + // 不返回错误,音量设置失败不应该阻止播放 + } + + // 开始播放 + printf("Starting playback...\n"); + if (!player->Play()) { + printf("ERROR: Failed to start playback\n"); + return -1; + } + + // 检查播放状态 + bool finalPlaying = player->IsPlaying(); + const char* finalStatus = player->GetStatus(); + printf("Final state - Status: %s, IsPlaying: %s\n", + finalStatus ? finalStatus : "null", finalPlaying ? "true" : "false"); + + printf("=== AudioPlayer playback started successfully ===\n"); + return 0; +} + +/** + * @brief 停止播放当前音频 + * @return 0: 成功, -1: 失败 + */ +int custom_stop_play_audio(void) +{ + printf("=== Starting AudioPlayer stop process ===\n"); + + OHOS::ACELite::AudioPlayer* player = OHOS::ACELite::AudioPlayer::GetInstance(); + if (!player) { + printf("ERROR: AudioPlayer instance is null\n"); + return -1; + } + + printf("AudioPlayer instance obtained successfully\n"); + + // 检查当前播放状态 + bool isPlaying = player->IsPlaying(); + const char* status = player->GetStatus(); + printf("Current status: %s, IsPlaying: %s\n", + status ? status : "null", isPlaying ? "true" : "false"); + + printf("Attempting to stop playback...\n"); + bool stopResult = player->Stop(); + printf("Stop result: %s\n", stopResult ? "SUCCESS" : "FAILED"); + + // 再次检查状态 + bool isStillPlaying = player->IsPlaying(); + const char* newStatus = player->GetStatus(); + printf("After stop - Status: %s, IsPlaying: %s\n", + newStatus ? newStatus : "null", isStillPlaying ? "true" : "false"); + + if (!stopResult) { + printf("ERROR: Failed to stop AudioPlayer\n"); + player->Stop(); + } + + + + printf("=== AudioPlayer stop process completed ===\n"); + return 0; } \ No newline at end of file diff --git a/code/sdk/zhihui/utilscpp/custom_utilscpp.h b/code/sdk/zhihui/utilscpp/custom_utilscpp.h index 74c5db69a..47b15938a 100644 --- a/code/sdk/zhihui/utilscpp/custom_utilscpp.h +++ b/code/sdk/zhihui/utilscpp/custom_utilscpp.h @@ -2,7 +2,7 @@ * @Author: penglei 1624952103@qq.com * @Date: 2024-07-09 20:22:54 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2025-08-20 15:13:20 + * @LastEditTime: 2025-09-16 15:27:29 * @FilePath: /FD230/code/sdk/drivers/peripheral/utilscpp/custom_utilscpp.h * @Description: * @@ -34,6 +34,9 @@ void custom_set_volume(uint8_t channel,int32_t sounding); void custom_factory_bt_scan_start(void); void custom_factory_bt_scan_stop(void); +int custom_play_audio(const char* filePath, float volume); +int custom_stop_play_audio(void); + /** * input: * func 函数指针 -- 2.17.1