#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};
//是否启用语音
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);
}
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");
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
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);