From: xue <2144439972@qq.com> Date: Sat, 13 Dec 2025 04:06:27 +0000 (+0800) Subject: 修改提醒音量与对话音量一致 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=bfe031415da1ffe6e8d4382f449413e07cf33183;p=mirrors%2FFD230.git 修改提醒音量与对话音量一致 --- diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_schedule.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_schedule.c index 1d37c999a..a5aa9df92 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_schedule.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_schedule.c @@ -8,6 +8,9 @@ #include "ai_media.h" #include "audio_stream_player.h" #include "ln_audio_simple.h" +#include +#include +#include "ln_api_interface.h" ScheduleReminder g_schedule_reminder = {0}; ScheduleReminderConfig g_schedule_reminder_config = {0}; @@ -211,6 +214,17 @@ void ln_parse_schedule_reminder(const char *json_buf, int json_len) //是否启用语音 if (g_schedule_reminder.enableVoice) { + // 在开始提醒前设置系统音量:将 ALARM_CLOCK 的音量设置为与UI中设置的音量相同的值 + // 因为待机状态下音量只是调节UI,并没有真正设置系统音量 + int32_t uiVolume = get_ui_volume(); + // 如果获取的音量为0或无效,使用默认值50 + if (uiVolume <= 0 || uiVolume > 100) { + uiVolume = 50; + } + // 将 ALARM_CLOCK 的音量设置为与UI中设置的音量相同的值 + AudioServiceSetVolume(AUDIO_STREAM_ALARM_CLOCK, uiVolume); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[SCHEDULE_REMINDER] Set ALARM_CLOCK volume to %d%% (from UI volume) before reminder\n", uiVolume); + // 目前是立即提醒的所以直接下载并播放 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[JSON_PARSE] download audio:执行下载并播放\n"); uapi_delete_files(LN_REMINDER_AUDIO_FILE); @@ -252,7 +266,7 @@ void ln_parse_schedule_reminder(const char *json_buf, int json_len) } else { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[JSON_PARSE] download audio:下载失败\n"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[JSON_PARSE] download audio:下载失败\n"); /* -------------------------------------------------------------------------- */ // 推送文本和日程提醒内容数据给ui WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[SCHEDULE_REMINDER] push text and schedule reminder content to ui\n"); diff --git a/code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.cpp b/code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.cpp index 19e0617f3..5ff00c002 100644 --- a/code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.cpp +++ b/code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.cpp @@ -336,6 +336,16 @@ void push_bluetooth_connect_notification(const char *bluetoothAddress) WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLUETOOTH_CONNECT] bluetoothAddress=%s", bluetoothAddress); SendMsgToUIService(HAND_BLUETOOTH_CONNECT_NOTIFY, 0, (void *)bluetoothAddress, (int32_t)strlen(bluetoothAddress)); } + +//获取UI中设置的音量值(未真正设置到系统的音量) +int32_t get_ui_volume(void) +{ + OHOS::ThunderBirdModel* model = OHOS::ThunderBirdModel::GetInstance(); + if (model == nullptr) { + return 50; // 默认值 + } + return model->m_volume; +} #ifdef __cplusplus }; #endif \ No newline at end of file diff --git a/code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.h b/code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.h index b3fe639ca..09163a87e 100644 --- a/code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.h +++ b/code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.h @@ -122,6 +122,8 @@ void push_dialogue_response_finished_notification(bool finished); void push_vad_initialized_notification(void); //通知进行蓝牙耳机连接操作 void push_bluetooth_connect_notification(const char *bluetoothAddress); +//获取UI中设置的音量值(未真正设置到系统的音量) +int32_t get_ui_volume(void); #ifdef __cplusplus } #endif diff --git a/code/sdk/zhihui/leiniao/ln_api_cpp/ln_audio_simple.cpp b/code/sdk/zhihui/leiniao/ln_api_cpp/ln_audio_simple.cpp index 95ff3a3db..e7ce3c125 100644 --- a/code/sdk/zhihui/leiniao/ln_api_cpp/ln_audio_simple.cpp +++ b/code/sdk/zhihui/leiniao/ln_api_cpp/ln_audio_simple.cpp @@ -185,18 +185,22 @@ int ln_audio_simple_play(const char *file_path) g_simple.player->EnableSingleLooping(false); g_simple.player->SetAudioStreamType(AUDIO_STREAM_ALARM_CLOCK); - ret = g_simple.player->Prepare(); - if (ret != 0) + // 在 Prepare 之前激活音频中断,因为 Prepare 时会创建音频流,需要有效的音频中断会话 + if (!EnsureAudioInterrupt()) { - printf("[LN_AUDIO_SIMPLE] Prepare failed: %d\n", ret); g_simple.player->Reset(); - return -5; + return -6; } - if (!EnsureAudioInterrupt()) + // 注意:音量设置已在提醒开始前完成(ln_api_schedule.c),这里不再重复设置 + + ret = g_simple.player->Prepare(); + if (ret != 0) { + printf("[LN_AUDIO_SIMPLE] Prepare failed: %d\n", ret); g_simple.player->Reset(); - return -6; + ClearAudioInterrupt(); + return -5; } ret = g_simple.player->SetAudioSessionId(g_simple.sessionId);