修改提醒音量与对话音量一致
authorxue <2144439972@qq.com>
Sat, 13 Dec 2025 04:06:27 +0000 (12:06 +0800)
committerxue <2144439972@qq.com>
Sat, 13 Dec 2025 04:06:27 +0000 (12:06 +0800)
code/sdk/zhihui/leiniao/imsl_ln/ln_api_schedule.c
code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.cpp
code/sdk/zhihui/leiniao/ln_api_cpp/ln_api_interface.h
code/sdk/zhihui/leiniao/ln_api_cpp/ln_audio_simple.cpp

index 1d37c99..a5aa9df 100644 (file)
@@ -8,6 +8,9 @@
 #include "ai_media.h"
 #include "audio_stream_player.h"
 #include "ln_audio_simple.h"
+#include <audio_service.h>
+#include <audio_base_type.h>
+#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");
index 19e0617..5ff00c0 100644 (file)
@@ -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
index b3fe639..09163a8 100644 (file)
@@ -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
index 95ff3a3..e7ce3c1 100644 (file)
@@ -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);