#include "graphic_service_wrapper.h"\r
#endif\r
\r
+#ifdef CUSTOM_UTILS\r
+#include "custom_utils.h"\r
+#endif\r
+\r
#define DISPLAY_AUTO_POWER_OFF_PERIOD_MS 5000\r
#define DISPLAY_DEFAULT_BRIGHTNESS 50\r
#define POWER_DISPLAY_QUEUE_MAX_SIZE 64\r
\r
static errcode_t power_display_turn_on_screen(void)\r
{\r
+#if defined(CUSTOM_UTILS) && defined(BOARD_LEINIAO)\r
+ uapi_lcd_backlight_on(50);\r
+#endif\r
#ifndef SUPPORT_OHOSFWK\r
message_type_t mt = TURN_ON_SCREEN_CMD;\r
uint32_t event_info = 0;\r
\r
static errcode_t power_display_turn_off_screen(void)\r
{\r
+#if defined(CUSTOM_UTILS) && defined(BOARD_LEINIAO)\r
+ uapi_lcd_backlight_off();\r
+#endif\r
#ifndef SUPPORT_OHOSFWK\r
message_type_t mt = TURN_OFF_SCREEN_CMD;\r
uint32_t event_info = 0;\r
# 'WEARABLE_LOG_DEBUG',
'SUPPORT_RC_CALIBRATION',
# 'PPG_HX3695',
- 'VIB_USE_PWM',
+ # 'VIB_USE_PWM',
'CONFIG_PWM_SUPPORT',
# 'ACC_LIS2DOC',
'ENABLE_CUSTOM_I2C',
{ HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO24
{ HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO25
- { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_HGPIO0 NC
+ { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_HGPIO0 NC
{ HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_HGPIO1 NC
{ HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_HGPIO2 NC
{ HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_HGPIO3 NC
- { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_HGPIO4 NC
+ { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_HGPIO4 NC
{ HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_HGPIO5 NC
#if (defined CFG_DRIVERS_NANDFLASH)
{ HAL_PIO_FUNC_QSPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_HGPIO6
{ HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L29 charge done info 检测是否充满电
{ HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L30 KP_MKIN1 唤醒 CAT1 ,输出
{ HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L31 KP_MKOUIT1 唤醒 蓝牙 ,输入
- { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_AGPIO_L32 NC
+ { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L32 NC
{ HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_R0 PRG_LED_POWER ON 心率等电源控制脚
{ HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_R1 SE_REST 安全芯片复位唤醒脚
// S_AGPIO_L23 CAT_1_PWR_ON ----- high power on
{ S_AGPIO_L23, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL },
// S_AGPIO_L28 Cat1 reset ---- low reset
- // { S_AGPIO_L28, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL },
+ // { S_AGPIO_L24, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL },
#endif
// S_AGPIO_L17 HX3507_INT
// { S_AGPIO_L17, HAL_GPIO_DIRECTION_INPUT, HAL_GPIO_LEVEL_LOW, 0, NULL },
// { S_AGPIO_L13, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL },
// S_AGPIO_L26 心率复位 PPG reset
- { S_AGPIO_L26, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL },
+ // { S_AGPIO_L26, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL },
// S_AGPIO_R0 PRG_LED_POWER ON 心率等电源控制脚
- { S_AGPIO_R0, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL },
+ // { S_AGPIO_R0, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL },
//S_AGPIO_L21 NTC_VDD_ON 给低打开 NTC上拉电源 ,默认关闭
{ S_AGPIO_L21, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_HIGH, 0, NULL },
{ S_AGPIO_R9, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL },
{ S_AGPIO_L20, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_HIGH, 0, NULL },
#endif
- //开机开启背光
- { S_AGPIO_L16, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_HIGH, 0, NULL },
+
+ // { S_AGPIO_L16, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_HIGH, 0, NULL },
//默认关闭马达
- { S_AGPIO_R2, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL },
+ { S_AGPIO_L32, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL },
+ { S_AGPIO_R0, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL },
+ { S_HGPIO4, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL },
+ { S_HGPIO0, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL },
+
+
//默认开启 EXT LDO V3.0 V1.8
// { S_AGPIO_L18, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_HIGH, 0, NULL },
{ S_AGPIO_L14, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_HIGH, 0, NULL },
//{ S_AGPIO_L19, HAL_GPIO_DIRECTION_INPUT, NULL, GPIO_INTERRUPT_DEDGE, cywee_int_callback },
#endif
/**S_AGPIO_R1 GPO alipay默认resetpin*/
- { S_AGPIO_R1, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_HIGH, 0, NULL },
+ // { S_AGPIO_R1, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_HIGH, 0, NULL },
#ifdef SUPPORT_CAT1_SERVICE
/**cat1 ring input key*/
// { S_AGPIO_L31, HAL_GPIO_DIRECTION_INPUT, NULL, GPIO_INTERRUPT_DEDGE, cat1_ring_isr_callback},
/** Moves the media position to the latest synchronization frame located after the given time position. */\r
PLAYER_SEEK_NEXT_SYNC,\r
/** Moves the media position to the latest synchronization frame located before or after the given time position. */\r
- PLAYER_SEEK_CLOSEST_SYNC,
- /** Moves the media position to the latest frame located before or after the given time position. */
- PLAYER_SEEK_CLOSEST,
-};
-
-/**
+ PLAYER_SEEK_CLOSEST_SYNC,\r
+ /** Moves the media position to the latest frame located before or after the given time position. */\r
+ PLAYER_SEEK_CLOSEST,\r
+};\r
+\r
+/**\r
* @brief Enumerates player states.\r
*\r
* @since 1.0\r
int32_t Rewind(int64_t mSeconds, int32_t mode);\r
\r
/**\r
- * @brief Sets the volume of the player.
- *
- * This function can be used during playback or pause. The value <b>0</b> indicates no sound, and <b>100</b>
- * 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.\r
+ *\r
+ * This function can be used during playback or pause. The value <b>0</b> indicates no sound, and <b>100</b>\r
+ * indicates the original volume.\r
+ *\r
+ * @param leftVolume Indicates the target volume of the left audio channel to set, ranging from 0 to 300.\r
+ * @param rightVolume Indicates the target volume of the right audio channel to set, ranging from 0 to 300.\r
* @return Returns <b>0</b> if the setting is successful; returns <b>-1</b> otherwise.\r
* @since 1.0\r
* @version 1.0\r
* @return Returns <b>true</b> if the player is looping; returns <b>false</b> otherwise.\r
* @since 1.0\r
* @version 1.0\r
- */
- bool IsSingleLooping();
-
- /**
- * @brief Obtains the player state.
- *
- * @param state Indicates the player state. For details, see {@link PlayerStates}.
- * @return Returns <b>0</b> if the player state is obtained; returns <b>-1</b> otherwise.
- * @since 1.0
- * @version 1.0
- */
- int32_t GetPlayerState(int32_t &state) const;
-
- /**
- * @brief Obtains the playback position, accurate to millisecond.
- *
+ */\r
+ bool IsSingleLooping();\r
+\r
+ /**\r
+ * @brief Obtains the player state.\r
+ *\r
+ * @param state Indicates the player state. For details, see {@link PlayerStates}.\r
+ * @return Returns <b>0</b> if the player state is obtained; returns <b>-1</b> otherwise.\r
+ * @since 1.0\r
+ * @version 1.0\r
+ */\r
+ int32_t GetPlayerState(int32_t &state) const;\r
+\r
+ /**\r
+ * @brief Obtains the playback position, accurate to millisecond.\r
+ *\r
* @param time Indicates the playback position.\r
* @return Returns <b>0</b> if the playback position is obtained; returns <b>-1</b> otherwise.\r
* @since 1.0\r
* @version 1.0\r
*/\r
int32_t GetDuration(int64_t &durationMs) const;\r
-
- /**
- * 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.
- *
+\r
+ /**\r
+ * Sets the playback speed.\r
+ *\r
+ * @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}\r
+ * @return Returns {@code 0} if the playback speed is set; returns {@code -1} otherwise.\r
+ */\r
+ int32_t SetPlaybackSpeed(float speed);\r
+ /**\r
+ * Obtains the playback speed.\r
+ *\r
+ * @param speed Indicates the playback speed.\r
+ * @return Returns {@code 0} if the playback speed is set; returns {@code -1} otherwise.\r
+ */\r
+ int32_t GetPlaybackSpeed(float &speed);\r
+ /**\r
+ * Sets the audio type.\r
+ *\r
+ * @param type Indicates the audio type.\r
+ * @return Returns {@code 0} if the setting is successful; returns {@code -1} otherwise.\r
+ */\r
+ int32_t SetAudioStreamType(int32_t type);\r
+ /**\r
+ * Obtains the audio type.\r
+ *\r
+ * @param type Indicates the audio type.\r
+ * @return Returns {@code 0} if the playback speed is set; returns {@code -1} otherwise.\r
+ */\r
+ int32_t GetAudioStreamType(int32_t &type);\r
+ /**\r
+ * @brief Restores the player to the initial state.\r
+ *\r
* @return Returns <b>0</b> if the player is restored; returns <b>-1</b> otherwise.\r
* @since 1.0\r
* @version 1.0\r
*\r
* @param cb Indicates the listener to register. For details, see {@link PlayerCallback}.\r
* @since 1.0\r
- * @version 1.0
- */
- void SetPlayerCallback(const std::shared_ptr<PlayerCallback> &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\r
+ */\r
+ void SetPlayerCallback(const std::shared_ptr<PlayerCallback> &cb);\r
+ /**\r
+ * set parameter through format, extended interface.\r
+ *\r
+ * @param params Indicates the extended-informations. Format see {@link Format}\r
+ * @return Returns {@code 0} if set parameter successfully; returns {@code -1} otherwise.\r
+ * @note not support on current version\r
+ */\r
+ int32_t SetParameter(const Format ¶ms);\r
+ /**\r
* get parameter through format, extended interface.\r
*\r
* @param params Indicates the extended-informations. Format see {@link Format}\r
*/\r
int32_t GetParameter(Format ¶ms);\r
/**\r
- * 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.\r
+ *\r
+ * @param totalTracks Indicates the total number of the tracks.\r
+ * @return Returns {@code 0} if set parameter successfully; returns {@code -1} otherwise.\r
+ */\r
int32_t GetTotalTracks(int32_t &totalTracks);\r
/**\r
* set audio sessionid.\r
- *
+ *\r
* @param sessionId indicates sessionid to be set.\r
* @return Returns {@code 0} if set parameter successfully; returns {@code -1} otherwise.\r
*/\r
int32_t SetAudioSessionId(uint32_t sessionId);\r
/**\r
* get current audio sessionid.\r
- *
+ *\r
* @param indicates sessionid.\r
* @return Returns {@code 0} if get parameter successfully; returns {@code -1} otherwise.\r
*/\r
int32_t GetAudioSessionId(uint32_t &sessionId);\r
/**\r
* set output device.\r
- *
+ *\r
* @param deviceId indicates device to be set.\r
* @return Returns {@code 0} if set parameter successfully; returns {@code -1} otherwise.\r
*/\r
int32_t SetOutputDevice(int32_t deviceId);\r
/**\r
* get current route device.\r
- *
+ *\r
* @param deviceId indicates the output device.\r
* @return Returns {@code 0} if get parameter successfully; returns {@code -1} otherwise.\r
*/\r
int32_t GetRoutedDeviceId(int32_t &deviceId);\r
\r
int32_t DumpInfo(PlayerDebugInfo *playerInfo);\r
-private:
- class PlayerImpl;
+private:\r
+ class PlayerImpl;\r
std::unique_ptr<PlayerImpl> impl_;\r
};\r
} // namespace Media\r
* @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:
*
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;
#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
}
#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;
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)
{
*/
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
+
/**
* @}
*/
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;
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;
}
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
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;
${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
#include "audio_manager.h"
#include "audio_base_type.h"
+#include "player_lite/js/builtin/include/audio_player.h"
+
#include "bts_br_gap.h"
#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<char*>(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
* @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:
*
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 函数指针