From c2a6ed26173e3ff2f86c1309d6489bd6b169a56f Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Sun, 20 Oct 2024 15:56:30 +0800 Subject: [PATCH] =?utf8?q?1.=E5=80=92=E8=AE=A1=E6=97=B6=E7=95=8C=E9=9D=A2?= =?utf8?q?=EF=BC=8CUI=E5=88=B7=E6=96=B0=E6=94=B9=E7=94=A8Notify=EF=BC=8C?= =?utf8?q?=E5=87=8F=E5=B0=91=E8=AF=AF=E5=B7=AE=202.=E5=80=92=E8=AE=A1?= =?utf8?q?=E6=97=B6=E5=93=8D=E9=93=83=E6=B5=81=E7=B1=BB=E5=9E=8B=E6=94=B9?= =?utf8?q?=E4=B8=BA=EF=BC=9AAUDIO=5FSTREAM=5FNOTIFICATION=5FSYSTEM=20?= =?utf8?q?=E6=94=AF=E6=8C=81a2dp=E6=92=AD=E6=94=BE=E6=97=B6=E6=B7=B7?= =?utf8?q?=E9=9F=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../include/MainCountDownPresenter.h | 7 +++-- .../nativeui/countdown/src/CountDownModel.cpp | 27 ++++++++++--------- .../countdown/src/MainCountDownPresenter.cpp | 14 ++++++++++ 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/countdown/include/MainCountDownPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/countdown/include/MainCountDownPresenter.h index c87e4a417..e16f7feef 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/countdown/include/MainCountDownPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/countdown/include/MainCountDownPresenter.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-07 18:15:53 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-20 10:17:35 + * @LastEditTime: 2024-10-19 17:07:09 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/countdown/include/MainCountDownPresenter.h */ #ifndef MAIN_COUNTDOWN_PRESENTER_H @@ -12,6 +12,7 @@ #include "Presenter.h" #include "MainCountDownView.h" #include "ui_resource_string.h" +#include "ModelListenerSample.h" /*倒计时的主界面*/ namespace OHOS { @@ -31,7 +32,8 @@ namespace OHOS public UIView::OnDragListener, UITimePicker::SelectedListener, public UICheckBox::OnChangeListener, - public RootView::OnKeyActListener + public RootView::OnKeyActListener, + public ModelListenerSample { public: MainCountDownPresenter(); @@ -52,6 +54,7 @@ namespace OHOS bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 bool OnChange(UICheckBox::UICheckBoxState state) override; void OnTimePickerStoped(UITimePicker &picker) override; + void Notify() override; std::string countdowntime{0}; std::string ringtime{0}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/countdown/src/CountDownModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/countdown/src/CountDownModel.cpp index 7518ec048..c15993234 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/countdown/src/CountDownModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/countdown/src/CountDownModel.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-07 18:15:53 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-10-11 16:17:52 + * @LastEditTime: 2024-10-20 11:49:21 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/countdown/src/CountDownModel.cpp */ #include "countdown/include/CountDownModel.h" @@ -174,7 +174,7 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] Player url:%s", uri.c_str()); playerCtr->SetSource(*source); /* --------------------------------- 4.配置播放器 -------------------------------- */ - playerCtr->SetAudioStreamType(AUDIO_STREAM_MUSIC); // 设置播放器的音频流类型 + playerCtr->SetAudioStreamType(AUDIO_STREAM_NOTIFICATION_SYSTEM); // 设置播放器的音频流类型 playerCtr->Prepare(); // 准备播放器对象以播放音频。 /* -------------------------------- 5.请求音频焦点 -------------------------------- */ AudioManager &amIntance = AudioManager::GetInstance(); @@ -192,7 +192,7 @@ namespace OHOS return OHOS_FAILURE; } playerInterruptListener->SetOwner(playerCtr); - interrupt = {AUDIO_STREAM_MUSIC, sessionId, playerInterruptListener}; + interrupt = {AUDIO_STREAM_NOTIFICATION_SYSTEM, sessionId, playerInterruptListener}; // 激活音频中断 5s超时 if (amIntance.ActivateAudioInterrupt(interrupt) == INTERRUPT_FAILED) { @@ -203,6 +203,7 @@ namespace OHOS playerCtr->SetAudioSessionId(sessionId); // 播放 playerCtr->Play(); + playerCtr->EnableSingleLooping(true); // 设置是否循环播放 return OHOS_SUCCESS; } @@ -436,14 +437,14 @@ namespace OHOS } } } - else - { - if (p_StartCountDownView) - { - // 更新显示 - p_StartCountDownView->GetShowCountDownTimelabel()->SetText(CountDownModel::GetInstance()->DisplayCountDownDuration()); - } - } + // else + // { + // if (p_StartCountDownView) + // { + // // 更新显示 + // p_StartCountDownView->GetShowCountDownTimelabel()->SetText(CountDownModel::GetInstance()->DisplayCountDownDuration()); + // } + // } return; } @@ -646,8 +647,8 @@ namespace OHOS void CountDownRingPlayerCallbackImpl::OnPlaybackComplete(void) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnPlaybackComplete"); - CountDownModel::GetInstance()->RequestStopRingtone(); - CountDownModel::GetInstance()->RequestStartRingtone(); + // CountDownModel::GetInstance()->RequestStopRingtone(); + // CountDownModel::GetInstance()->RequestStartRingtone(); } void CountDownRingPlayerCallbackImpl::OnError(int32_t errorType, int32_t errorCode) diff --git a/code/sdk/application/wearable/fd230app/nativeui/countdown/src/MainCountDownPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/countdown/src/MainCountDownPresenter.cpp index 134887383..da464782c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/countdown/src/MainCountDownPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/countdown/src/MainCountDownPresenter.cpp @@ -295,4 +295,18 @@ namespace OHOS CountDownModel::GetInstance()->SetCountDownTime(picker.GetSelectValue()); // 设置倒计时时间 CountDownModel::GetInstance()->SetRingTime(picker.GetSelectValue()); // 设置响铃时间 } + void MainCountDownPresenter::Notify() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainCountDownPresenter::Notify"); + if(CountDownModel::GetInstance()->CountDownTimerIsEnd()) // 倒计时timer已经停止直接退出不刷新 + { + return; + } + StartCountDownView *p_StartCountDownView = StartCountDownView::GetInstance(); + if (p_StartCountDownView && p_StartCountDownView->GetShowCountDownTimelabel()) + { + // 更新显示 + p_StartCountDownView->GetShowCountDownTimelabel()->SetText(CountDownModel::GetInstance()->DisplayCountDownDuration()); + } + } } \ No newline at end of file -- 2.17.1