From: luozheng <1732036298@qq.com> Date: Sat, 21 Sep 2024 10:36:11 +0000 (+0800) Subject: #217,解决,本地音乐选择手机音乐,手表在播放手机端的音乐时,调节手表端音量不起作用bug X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=9ac9dc32413edcb7848ec2589fd6af7933d86764;p=mirrors%2FFD230.git #217,解决,本地音乐选择手机音乐,手表在播放手机端的音乐时,调节手表端音量不起作用bug 取消秒表界面的长亮屏操作 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothHeadsetEvent.h b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothHeadsetEvent.h index 8e5341d74..2253e6d41 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothHeadsetEvent.h +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothHeadsetEvent.h @@ -37,6 +37,7 @@ void PressButtonStatusCallback(td_u32 keyOperation, td_u32 keyValue); void ConnCtStateChangedCallback(const bd_addr_t *bdAddr, profile_connect_state_t state); void ConnectTgStateChangedCallback(const bd_addr_t *bdAddr, profile_connect_state_t state); void InitBtHeadsetEvent(void); +void BtAvrcpVolumeChangedSyncMedia(uint8_t a2dp_volume); #ifdef __cplusplus } diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothHeadsetEvent.cpp b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothHeadsetEvent.cpp index 00057bc20..0ab8b0a74 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothHeadsetEvent.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothHeadsetEvent.cpp @@ -98,8 +98,15 @@ void BtAvrcpTgNotifyVolumeChangedProc(uint8_t a2dp_volume) int32_t audio_volume = a2dp_volume * BT_A2DP_MEDIA_VOL_LEVEL / AVRCP_ABSOLUTE_VOLUME_PERCENTAGE_100; WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "NotifyVolume = %d", audio_volume); AudioManager::GetInstance().SetVolume(AUDIO_STREAM_MUSIC, audio_volume); // 耳机连接手表场景调节手表音量 + /* ---------------------------- 若当前音乐播放器为手机音乐则同步更新音乐播放器的声音进度条 --------------------------- */ + if(PlayersModel::GetInstance()->GetMusicSource()) + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(&OHOS::PlayersModel::UpdateVolumeValue, OHOS::PlayersModel::GetInstance())); + } + /* -------------------------------------------------------------------------- */ } +//根据传入的按键操作类型和值,执行相应的操作并通知媒体状态变化 void UsingPressButtonStatusCallback(td_u32 keyOperation, td_u32 keyValue) { bt_avrcp_tg_evt_status_param event; @@ -407,6 +414,7 @@ static void BtAvrcpCtHdlNotifyVolumeRspCbk(avrcp_ct_notification_value_cb_t *not BtAvrcpTgNotifyVolumeChangedProc((uint8_t)notification->volume); } +//收到来自TG返回的Notification时回调函数 static void BtAvrcpCtNotificationCallback( const bd_addr_t *bd_addr, avrcp_notify_event_t event_id, avrcp_ct_notification_value_cb_t *notification) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/include/VolumeSettingPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/main/include/VolumeSettingPresenter.h index 5bdd51a5e..a63c46037 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/include/VolumeSettingPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/main/include/VolumeSettingPresenter.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-08-05 15:20:02 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-10 14:31:56 + * @LastEditTime: 2024-09-21 18:17:27 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/main/include/VolumeSettingPresenter.h */ @@ -38,6 +38,7 @@ typedef enum : uint8_t { class VolumeSettingView; class VolumeSliderEventListener : public UISlider::UISliderEventListener, public UIView::OnClickListener, + public UIView::OnRotateListener, public UIView::OnDragListener { public: VolumeSliderEventListener(VolumeSettingView *volumeSetting); @@ -48,6 +49,7 @@ public: void ChangeVolume(VolumeChangeStatus status); bool OnClick(UIView& view, const ClickEvent& event) override; bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnRotateEnd(UIView& view, const RotateEvent& event); void SetPlayerCoefficients(int16_t value); void BtAndLocalVolumeSet(int16_t sounding); private: diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp index ba20d7952..3469217d3 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp @@ -376,6 +376,7 @@ namespace OHOS { return; } + if(PlayersModel::GetInstance()->GetMusicSource() == false) { int32_t playerState; PlayersModel::GetInstance()->GetPlayerCtr()->GetPlayerState(playerState); state_ = playersView->GetPlayerButtonState(); @@ -387,6 +388,7 @@ namespace OHOS { playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::SELECTED); } + } if (state_ == UICheckBox::UICheckBoxState::SELECTED) { PlayersModel::GetInstance()->GetPlayerCtr()->GetCurrentTime(playerCurrentTime_); diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/VolumeSettingPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/VolumeSettingPresenter.cpp index da0b478e4..89b71bcc3 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/VolumeSettingPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/VolumeSettingPresenter.cpp @@ -135,6 +135,13 @@ void VolumeSliderEventListener::BtAndLocalVolumeSet(int16_t sounding) WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "avrcp volume = %d", volume); (void)avrcp_ct_set_absolute_volume(&(g_avrcp_srv_inf.bd_addr), volume); // 手表音量设置同步远端BT音量 } + /* -------------------------- 若ct或tg端是已连接状态且当前为手机音乐 ------------------------- */ + if (PlayersModel::GetInstance()->get_avrcp_ct_or_tg_is_connected() && PlayersModel::GetInstance()->GetMusicSource()) + { + uint8_t volume = sounding * AVRCP_ABSOLUTE_VOLUME_PERCENTAGE_100 / 100; // 100:本地音量最大值 + BtAvrcpVolumeChangedSyncMedia(volume);// 手表音量设置同步手机音量 + } + /* -------------------------------------------------------------------------- */ WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "audio volume = %d", sounding); AudioManager::GetInstance().SetVolume(AUDIO_STREAM_MUSIC, sounding); // 本地音量设置 } @@ -156,6 +163,21 @@ void VolumeSliderEventListener::OnChange(int32_t value) // ChangeVolume(VOLUMEDRAG); } +bool VolumeSliderEventListener::OnRotateEnd(UIView& view, const RotateEvent& event) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "VolumeSliderEventListener::OnRotateEnd"); + UISlider *slider = dynamic_cast(&view); + UISlider *progress = volumeSettingView->GetProgress(); + if (slider != nullptr && progress != nullptr) + { + if (slider == progress) + { + ChangeVolume(VOLUMEDRAG); + } + } + return true; +} + bool VolumeSliderEventListener::OnDrag(UIView& view, const DragEvent& event) { if (strcmp(view.GetViewId(), VOLUME_VIEW) == 0) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/VolumeSettingView.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/VolumeSettingView.cpp index 44dd657e5..cd07875bd 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/VolumeSettingView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/VolumeSettingView.cpp @@ -32,6 +32,7 @@ VolumeSettingView::~VolumeSettingView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "VolumeSettingView::~VolumeSettingView"); RemoveAll(); + FocusManager::GetInstance()->ClearFocus(); if (listener != nullptr) { delete listener; listener = nullptr; @@ -79,7 +80,8 @@ bool VolumeSettingView::SetUpVolume(void) progress->SetForegroundStyle(STYLE_LINE_CAP, CapType::CAP_ROUND); progress->SetSliderColor(Color::GetColorFromRGBA(0x19, 0x19, 0x19, 0xff), Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xff)); progress->SetForegroundStyle(STYLE_BACKGROUND_OPA, 0xff); - progress->RequestFocus(); + FocusManager::GetInstance()->RequestFocus(progress); + FocusManager::GetInstance()->RequestFocusByDirection(FOCUS_DIRECTION_DOWN); progress->SetRotateFactor(1.0); VolumeVetor = new UIImageView(); @@ -102,6 +104,7 @@ bool VolumeSettingView::SetUpVolume(void) progress->SetSliderEventListener(listener); progress->SetOnClickListener(listener); progress->SetOnDragListener(listener); + progress->SetOnRotateListener(listener); progress->SetKnobStyle(StyleDefault::GetSliderKnobStyle()); SetViewId(VOLUME_VIEW); SetOnDragListener(listener); diff --git a/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersModel.h b/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersModel.h index 3e574f8f9..1e0da28c5 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersModel.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-08-05 15:20:03 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-29 18:33:50 + * @LastEditTime: 2024-09-21 17:01:40 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/player/include/PlayersModel.h */ @@ -105,6 +105,9 @@ public: void PlayerMusic_StopTimer(void); void SetCircleProgress(); void UpdatePlayerProcess(void); + void UpdateVolumeValue(void); + bool get_avrcp_ct_or_tg_is_connected(void); + void set_phone_music_play_state(avrcp_key_operation_t notify); private: bool musicSourceFlag{false};//音乐来源标志:false:默认为手表音乐,true:手机音乐 int64_t playerCurrentTime_{0}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp index 0cb06b536..825fd2a33 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp @@ -824,7 +824,7 @@ bool PlayersModel::GetCurrentMusicIsPlaying(void) if(type) { bool phonebluetoothcon = SettingModel::GetInstance().GetPhoneConnectStatus(); // 获取手机连接状态 bool a2dp = uapi_a2dp_snk_get_device_connect_state(); // 获取a2dp连接状态 - if(g_PlayerTimes < 2) /*3秒切换时间*/ + if(g_PlayerTimes < 3) /*3秒切换时间*/ { if (!phonebluetoothcon) { @@ -841,7 +841,7 @@ bool PlayersModel::GetCurrentMusicIsPlaying(void) } } else { - if(g_PlayerTimes < 2) /*3秒切换时间*/ + if(g_PlayerTimes < 3) /*3秒切换时间*/ { playersView->ChangeView(PlayersView::MUISC_CONNECTING, PlayersView::MUSIC_SOURCE_VIEW); } @@ -958,6 +958,68 @@ bool PlayersModel::GetCurrentMusicIsPlaying(void) } SetCircleProgress(); } + + void PlayersModel::UpdateVolumeValue(void) + { + if(PlayersView::GetInstance()) + { + PlayersView::GetInstance()->UpdateVolumeValue(); + } + } + + bool PlayersModel::get_avrcp_ct_or_tg_is_connected(void) + { + bd_addr_t bdAddr={0}; + uapi_get_br_address(&bdAddr); //获取手机蓝牙地址 + int32_t connCtState = avrcp_ct_get_device_connect_state(&bdAddr); + int32_t connTgState = avrcp_tg_get_device_connect_state(&bdAddr); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtAndLocalVolumeSet addr: %02x%02x%02x%02x%02x%02x ", + bdAddr.addr[5], bdAddr.addr[4], bdAddr.addr[3], /* 5 4 3 idx */ + bdAddr.addr[2], bdAddr.addr[1], bdAddr.addr[0]); /* 2 1 0 idx */ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "connCtState:%x", connCtState); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "connTgState:%x", connTgState); + if (connCtState == PROFILE_STATE_CONNECTED || connTgState == PROFILE_STATE_CONNECTED) + { + return true; + } + return false; + } + + void PlayersModel::set_phone_music_play_state(avrcp_key_operation_t notify) + { + #if 0 + int ret; + int playerState; + bd_addr_t bdAddr={0}; + uapi_get_br_address(&bdAddr); //获取手机蓝牙地址 + int a2dp_play_stat = a2dp_src_get_playing_state(&bdAddr); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[a2dp_play_stat]%d", a2dp_play_stat); + switch(notify) + { + case AVRCP_KEY_PLAY://播放 + if(a2dp_play_stat == A2DP_IS_PLAYING) + return; + ret = a2dp_src_start_playing(&bdAddr);//设置手机音乐的状态为播放 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[a2dp_src_start_playing],ret:%x", ret); + playerState = AVRCP_PLAY_STATUS_PLAYING; + break; + case AVRCP_KEY_STOP: //停止 + ret = a2dp_src_stop_playing(&bdAddr);//设置手机的状态停止 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[a2dp_src_stop_playing],ret:%x", ret); + playerState = AVRCP_PLAY_STATUS_STOPPED; + break; + case AVRCP_KEY_PAUSE://暂停 + ret = a2dp_src_suspend_playing(&bdAddr);//设置手机的状态暂停 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[a2dp_src_suspend_playing],ret:%x", ret); + playerState = AVRCP_PLAY_STATUS_PAUSED; + break; + default: + playerState = AVRCP_PLAY_STATUS_STOPPED; + break; + } + avrcp_tg_notify_playback_status_changed((unsigned char)(playerState)); + #endif + } } #ifdef __cplusplus diff --git a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersPresenter.cpp index 3d5c1cb4d..a4b3cafa4 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersPresenter.cpp @@ -580,13 +580,13 @@ void ButtonOnClickListener::PlayerButtonOnClick() return; } - if(PlayersListGroup::GetInstance()->GetCase().IsEmpty()) //若当前歌曲列表为空他跳转到音乐列表进行提示 + if(PlayersListGroup::GetInstance()->GetCase().IsEmpty() && !PlayersModel::GetInstance()->GetMusicSource()) //若当前歌曲列表为空且为本地音乐他跳转到音乐列表进行提示 { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "current playersCaseList_ is empty!!"); playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED); playersView->ChangeView(PlayersView::MAIN_MUSICPLAYER_VIEW,PlayersView::MUSIC_LIST_VIEW); return; - } + } WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "play_or_pause_Button OnClick"); uint8_t state = UICheckBox::UICheckBoxState::MAX_STATUS_NUM; @@ -615,6 +615,19 @@ void ButtonOnClickListener::PlayerButtonOnClick() WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[PlayerButtonOnClick] calling phone"); return; } + if(PlayersModel::GetInstance()->get_avrcp_ct_or_tg_is_connected() && PlayersModel::GetInstance()->GetMusicSource()) + { + if (state == UICheckBox::UICheckBoxState::SELECTED) + { + PlayersModel::GetInstance()->set_phone_music_play_state(AVRCP_KEY_PLAY); + } + else if (state == UICheckBox::UICheckBoxState::UNSELECTED) + { + PlayersModel::GetInstance()->set_phone_music_play_state(AVRCP_KEY_PAUSE); + } + return; + } + if (state == UICheckBox::UICheckBoxState::SELECTED) { /* start play */ PlayersModel::GetInstance()->ConnectBtAndLocalPlay(connCtState, connTgState, playerState); diff --git a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchPresenter.cpp index f4e911078..b950eec17 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchPresenter.cpp @@ -38,7 +38,7 @@ namespace OHOS void MainStopWatchPresenter::OnStart() { Presenter::OnStart(); - ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 长亮屏 + // ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 长亮屏 } void MainStopWatchPresenter::OnPause(void) @@ -56,7 +56,7 @@ namespace OHOS void MainStopWatchPresenter::OnStop(void) { Presenter::OnStop(); - ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); // 取消长亮屏 + // ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); // 取消长亮屏 } /// @brief 设置复选框和按钮