1a3e0fd82Sopenharmony_ci/* 2a3e0fd82Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3a3e0fd82Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4a3e0fd82Sopenharmony_ci * you may not use this file except in compliance with the License. 5a3e0fd82Sopenharmony_ci * You may obtain a copy of the License at 6a3e0fd82Sopenharmony_ci * 7a3e0fd82Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8a3e0fd82Sopenharmony_ci * 9a3e0fd82Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10a3e0fd82Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11a3e0fd82Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12a3e0fd82Sopenharmony_ci * See the License for the specific language governing permissions and 13a3e0fd82Sopenharmony_ci * limitations under the License. 14a3e0fd82Sopenharmony_ci */ 15a3e0fd82Sopenharmony_ci 16a3e0fd82Sopenharmony_ci#include "components/ui_video.h" 17a3e0fd82Sopenharmony_ci#include "securec.h" 18a3e0fd82Sopenharmony_ci 19a3e0fd82Sopenharmony_ci#ifndef VERSION_LITE 20a3e0fd82Sopenharmony_cinamespace OHOS { 21a3e0fd82Sopenharmony_ciUIVideo::UIVideo() 22a3e0fd82Sopenharmony_ci{ 23a3e0fd82Sopenharmony_ci SetTouchable(true); 24a3e0fd82Sopenharmony_ci SetOnTouchListener(this); 25a3e0fd82Sopenharmony_ci} 26a3e0fd82Sopenharmony_ci 27a3e0fd82Sopenharmony_ciUIVideo::~UIVideo() 28a3e0fd82Sopenharmony_ci{ 29a3e0fd82Sopenharmony_ci if (videoPlayer_ != nullptr) { 30a3e0fd82Sopenharmony_ci videoPlayer_->Stop(); 31a3e0fd82Sopenharmony_ci videoPlayer_->Reset(); 32a3e0fd82Sopenharmony_ci videoPlayer_->Release(); 33a3e0fd82Sopenharmony_ci } 34a3e0fd82Sopenharmony_ci if (sliderAnimator_ != nullptr) { 35a3e0fd82Sopenharmony_ci delete sliderAnimator_; 36a3e0fd82Sopenharmony_ci sliderAnimator_ = nullptr; 37a3e0fd82Sopenharmony_ci } 38a3e0fd82Sopenharmony_ci if (surfaceView_ != nullptr) { 39a3e0fd82Sopenharmony_ci Remove(surfaceView_); 40a3e0fd82Sopenharmony_ci delete surfaceView_; 41a3e0fd82Sopenharmony_ci surfaceView_ = nullptr; 42a3e0fd82Sopenharmony_ci } 43a3e0fd82Sopenharmony_ci DeleteController(); 44a3e0fd82Sopenharmony_ci} 45a3e0fd82Sopenharmony_ci 46a3e0fd82Sopenharmony_cibool UIVideo::SetSrc(const char* source) 47a3e0fd82Sopenharmony_ci{ 48a3e0fd82Sopenharmony_ci if (source == nullptr) { 49a3e0fd82Sopenharmony_ci return false; 50a3e0fd82Sopenharmony_ci } 51a3e0fd82Sopenharmony_ci 52a3e0fd82Sopenharmony_ci InitVideo(); 53a3e0fd82Sopenharmony_ci src_ = source; 54a3e0fd82Sopenharmony_ci std::string uri(source); 55a3e0fd82Sopenharmony_ci std::map<std::string, std::string> header; 56a3e0fd82Sopenharmony_ci Source videoSource(uri, header); 57a3e0fd82Sopenharmony_ci if (videoPlayer_ != nullptr) { 58a3e0fd82Sopenharmony_ci int32_t ret = videoPlayer_->SetSource(videoSource); 59a3e0fd82Sopenharmony_ci if (ret == 0) { 60a3e0fd82Sopenharmony_ci return true; 61a3e0fd82Sopenharmony_ci } 62a3e0fd82Sopenharmony_ci } 63a3e0fd82Sopenharmony_ci return false; 64a3e0fd82Sopenharmony_ci} 65a3e0fd82Sopenharmony_ci 66a3e0fd82Sopenharmony_cibool UIVideo::Prepare() 67a3e0fd82Sopenharmony_ci{ 68a3e0fd82Sopenharmony_ci if (src_ == nullptr) { 69a3e0fd82Sopenharmony_ci return false; 70a3e0fd82Sopenharmony_ci } 71a3e0fd82Sopenharmony_ci if (videoPlayer_ == nullptr) { 72a3e0fd82Sopenharmony_ci return false; 73a3e0fd82Sopenharmony_ci } 74a3e0fd82Sopenharmony_ci 75a3e0fd82Sopenharmony_ci int32_t ret = videoPlayer_->Prepare(); 76a3e0fd82Sopenharmony_ci if (ret != 0) { 77a3e0fd82Sopenharmony_ci return false; 78a3e0fd82Sopenharmony_ci } 79a3e0fd82Sopenharmony_ci SetVolume(DEFAULT_VOLUME, DEFAULT_VOLUME); 80a3e0fd82Sopenharmony_ci videoPlayer_->GetDuration(duration_); 81a3e0fd82Sopenharmony_ci if (totalTimeLabel_ != nullptr) { 82a3e0fd82Sopenharmony_ci char timer[10] = {0}; // 10:timer length 83a3e0fd82Sopenharmony_ci if (!GetTimerFromMSecond(duration_, timer, sizeof(timer))) { 84a3e0fd82Sopenharmony_ci return false; 85a3e0fd82Sopenharmony_ci } 86a3e0fd82Sopenharmony_ci totalTimeLabel_->SetText(&timer[0]); 87a3e0fd82Sopenharmony_ci } 88a3e0fd82Sopenharmony_ci 89a3e0fd82Sopenharmony_ci if (titleLabel_ != nullptr) { 90a3e0fd82Sopenharmony_ci const char* fileName = nullptr; 91a3e0fd82Sopenharmony_ci fileName = strrchr(src_, '/'); 92a3e0fd82Sopenharmony_ci if (fileName != nullptr) { 93a3e0fd82Sopenharmony_ci titleLabel_->SetText(fileName + 1); 94a3e0fd82Sopenharmony_ci } 95a3e0fd82Sopenharmony_ci } 96a3e0fd82Sopenharmony_ci if (sliderAnimatorCallback_) { 97a3e0fd82Sopenharmony_ci sliderAnimatorCallback_->SetDuration(duration_); 98a3e0fd82Sopenharmony_ci } 99a3e0fd82Sopenharmony_ci SetSurfaceInfo(); 100a3e0fd82Sopenharmony_ci 101a3e0fd82Sopenharmony_ci playerListener_ = std::make_shared<PlayerListener>(); 102a3e0fd82Sopenharmony_ci playerListener_->SetVideoPlayer(this); 103a3e0fd82Sopenharmony_ci videoPlayer_->SetPlayerCallback(playerListener_); 104a3e0fd82Sopenharmony_ci return true; 105a3e0fd82Sopenharmony_ci} 106a3e0fd82Sopenharmony_ci 107a3e0fd82Sopenharmony_cibool UIVideo::Play() 108a3e0fd82Sopenharmony_ci{ 109a3e0fd82Sopenharmony_ci if (videoPlayer_ != nullptr) { 110a3e0fd82Sopenharmony_ci int32_t ret = videoPlayer_->Play(); 111a3e0fd82Sopenharmony_ci if (ret == 0) { 112a3e0fd82Sopenharmony_ci if (sliderAnimator_ != nullptr) { 113a3e0fd82Sopenharmony_ci sliderAnimator_->Start(); 114a3e0fd82Sopenharmony_ci } 115a3e0fd82Sopenharmony_ci if (pauseButton_ != nullptr) { 116a3e0fd82Sopenharmony_ci pauseButton_->SetVisible(false); 117a3e0fd82Sopenharmony_ci } 118a3e0fd82Sopenharmony_ci if (playButton_ != nullptr) { 119a3e0fd82Sopenharmony_ci playButton_->SetState(true); 120a3e0fd82Sopenharmony_ci } 121a3e0fd82Sopenharmony_ci if (surfaceView_ != nullptr) { 122a3e0fd82Sopenharmony_ci surfaceView_->SetVisible(true); 123a3e0fd82Sopenharmony_ci } 124a3e0fd82Sopenharmony_ci if (videoPlayerListener_ != nullptr) { 125a3e0fd82Sopenharmony_ci videoPlayerListener_->OnPlaybackPlay(); 126a3e0fd82Sopenharmony_ci } 127a3e0fd82Sopenharmony_ci return true; 128a3e0fd82Sopenharmony_ci } 129a3e0fd82Sopenharmony_ci } 130a3e0fd82Sopenharmony_ci return false; 131a3e0fd82Sopenharmony_ci} 132a3e0fd82Sopenharmony_ci 133a3e0fd82Sopenharmony_cibool UIVideo::IsPlaying() 134a3e0fd82Sopenharmony_ci{ 135a3e0fd82Sopenharmony_ci if (videoPlayer_ != nullptr) { 136a3e0fd82Sopenharmony_ci return videoPlayer_->IsPlaying(); 137a3e0fd82Sopenharmony_ci } 138a3e0fd82Sopenharmony_ci return false; 139a3e0fd82Sopenharmony_ci} 140a3e0fd82Sopenharmony_ci 141a3e0fd82Sopenharmony_cibool UIVideo::Pause() 142a3e0fd82Sopenharmony_ci{ 143a3e0fd82Sopenharmony_ci if (videoPlayer_ != nullptr) { 144a3e0fd82Sopenharmony_ci int32_t ret = videoPlayer_->Pause(); 145a3e0fd82Sopenharmony_ci if (ret == 0) { 146a3e0fd82Sopenharmony_ci if (sliderAnimator_ != nullptr) { 147a3e0fd82Sopenharmony_ci sliderAnimator_->Pause(); 148a3e0fd82Sopenharmony_ci } 149a3e0fd82Sopenharmony_ci if (playButton_ != nullptr) { 150a3e0fd82Sopenharmony_ci playButton_->SetState(false); 151a3e0fd82Sopenharmony_ci } 152a3e0fd82Sopenharmony_ci if (pauseButton_ != nullptr) { 153a3e0fd82Sopenharmony_ci pauseButton_->SetVisible(true); 154a3e0fd82Sopenharmony_ci } 155a3e0fd82Sopenharmony_ci if (videoPlayerListener_ != nullptr) { 156a3e0fd82Sopenharmony_ci videoPlayerListener_->OnPlaybackPause(); 157a3e0fd82Sopenharmony_ci } 158a3e0fd82Sopenharmony_ci return true; 159a3e0fd82Sopenharmony_ci } 160a3e0fd82Sopenharmony_ci } 161a3e0fd82Sopenharmony_ci return false; 162a3e0fd82Sopenharmony_ci} 163a3e0fd82Sopenharmony_ci 164a3e0fd82Sopenharmony_cibool UIVideo::Stop() 165a3e0fd82Sopenharmony_ci{ 166a3e0fd82Sopenharmony_ci if (videoPlayer_ != nullptr) { 167a3e0fd82Sopenharmony_ci int32_t ret = videoPlayer_->Stop(); 168a3e0fd82Sopenharmony_ci if (ret == 0) { 169a3e0fd82Sopenharmony_ci if (sliderAnimator_ != nullptr) { 170a3e0fd82Sopenharmony_ci sliderAnimator_->Stop(); 171a3e0fd82Sopenharmony_ci } 172a3e0fd82Sopenharmony_ci if (playSlider_ != nullptr) { 173a3e0fd82Sopenharmony_ci playSlider_->SetValue(0); 174a3e0fd82Sopenharmony_ci } 175a3e0fd82Sopenharmony_ci if (currentTimeLabel_ != nullptr) { 176a3e0fd82Sopenharmony_ci currentTimeLabel_->SetText("00:00:00"); 177a3e0fd82Sopenharmony_ci } 178a3e0fd82Sopenharmony_ci if (totalTimeLabel_ != nullptr) { 179a3e0fd82Sopenharmony_ci totalTimeLabel_->SetText("00:00:00"); 180a3e0fd82Sopenharmony_ci } 181a3e0fd82Sopenharmony_ci if (playButton_ != nullptr) { 182a3e0fd82Sopenharmony_ci playButton_->SetState(false); 183a3e0fd82Sopenharmony_ci } 184a3e0fd82Sopenharmony_ci if (pauseButton_ != nullptr) { 185a3e0fd82Sopenharmony_ci pauseButton_->SetVisible(true); 186a3e0fd82Sopenharmony_ci } 187a3e0fd82Sopenharmony_ci if (surfaceView_ != nullptr) { 188a3e0fd82Sopenharmony_ci surfaceView_->SetVisible(false); 189a3e0fd82Sopenharmony_ci } 190a3e0fd82Sopenharmony_ci if (videoPlayerListener_ != nullptr) { 191a3e0fd82Sopenharmony_ci videoPlayerListener_->OnPlaybackStop(); 192a3e0fd82Sopenharmony_ci } 193a3e0fd82Sopenharmony_ci return true; 194a3e0fd82Sopenharmony_ci } 195a3e0fd82Sopenharmony_ci } 196a3e0fd82Sopenharmony_ci return false; 197a3e0fd82Sopenharmony_ci} 198a3e0fd82Sopenharmony_ci 199a3e0fd82Sopenharmony_cibool UIVideo::Rewind(int64_t mSeconds) 200a3e0fd82Sopenharmony_ci{ 201a3e0fd82Sopenharmony_ci if (videoPlayer_ != nullptr) { 202a3e0fd82Sopenharmony_ci int32_t ret = videoPlayer_->Rewind(mSeconds, PLAYER_SEEK_PREVIOUS_SYNC); 203a3e0fd82Sopenharmony_ci if (ret == 0) { 204a3e0fd82Sopenharmony_ci return true; 205a3e0fd82Sopenharmony_ci } 206a3e0fd82Sopenharmony_ci } 207a3e0fd82Sopenharmony_ci return false; 208a3e0fd82Sopenharmony_ci} 209a3e0fd82Sopenharmony_ci 210a3e0fd82Sopenharmony_cibool UIVideo::SetVolume(float leftVolume, float rightVolume) 211a3e0fd82Sopenharmony_ci{ 212a3e0fd82Sopenharmony_ci if (videoPlayer_ != nullptr) { 213a3e0fd82Sopenharmony_ci int32_t ret = videoPlayer_->SetVolume(leftVolume * MAX_VOLUME, rightVolume * MAX_VOLUME); 214a3e0fd82Sopenharmony_ci if (ret == 0) { 215a3e0fd82Sopenharmony_ci leftVolumeValue_ = leftVolume; 216a3e0fd82Sopenharmony_ci rightVolumeValue_ = rightVolume; 217a3e0fd82Sopenharmony_ci if (volumeButton_ != nullptr) { 218a3e0fd82Sopenharmony_ci if ((leftVolumeValue_ == 0) && (rightVolumeValue_ == 0)) { 219a3e0fd82Sopenharmony_ci volumeButton_->SetState(true); 220a3e0fd82Sopenharmony_ci } else { 221a3e0fd82Sopenharmony_ci volumeButton_->SetState(false); 222a3e0fd82Sopenharmony_ci } 223a3e0fd82Sopenharmony_ci } 224a3e0fd82Sopenharmony_ci return true; 225a3e0fd82Sopenharmony_ci } 226a3e0fd82Sopenharmony_ci } 227a3e0fd82Sopenharmony_ci return false; 228a3e0fd82Sopenharmony_ci} 229a3e0fd82Sopenharmony_ci 230a3e0fd82Sopenharmony_cibool UIVideo::IsSingleLooping() 231a3e0fd82Sopenharmony_ci{ 232a3e0fd82Sopenharmony_ci if (videoPlayer_ != nullptr) { 233a3e0fd82Sopenharmony_ci return videoPlayer_->IsSingleLooping(); 234a3e0fd82Sopenharmony_ci } 235a3e0fd82Sopenharmony_ci return false; 236a3e0fd82Sopenharmony_ci} 237a3e0fd82Sopenharmony_ci 238a3e0fd82Sopenharmony_cibool UIVideo::GetCurrentTime(int64_t& time) 239a3e0fd82Sopenharmony_ci{ 240a3e0fd82Sopenharmony_ci if (videoPlayer_ != nullptr) { 241a3e0fd82Sopenharmony_ci int32_t ret = videoPlayer_->GetCurrentTime(time); 242a3e0fd82Sopenharmony_ci if (ret == 0) { 243a3e0fd82Sopenharmony_ci return true; 244a3e0fd82Sopenharmony_ci } 245a3e0fd82Sopenharmony_ci } 246a3e0fd82Sopenharmony_ci return false; 247a3e0fd82Sopenharmony_ci} 248a3e0fd82Sopenharmony_ci 249a3e0fd82Sopenharmony_cibool UIVideo::GetDuration(int64_t& durationMs) 250a3e0fd82Sopenharmony_ci{ 251a3e0fd82Sopenharmony_ci if (videoPlayer_ != nullptr) { 252a3e0fd82Sopenharmony_ci int32_t ret = videoPlayer_->GetDuration(durationMs); 253a3e0fd82Sopenharmony_ci if (ret == 0) { 254a3e0fd82Sopenharmony_ci return true; 255a3e0fd82Sopenharmony_ci } 256a3e0fd82Sopenharmony_ci } 257a3e0fd82Sopenharmony_ci return false; 258a3e0fd82Sopenharmony_ci} 259a3e0fd82Sopenharmony_ci 260a3e0fd82Sopenharmony_civoid UIVideo::SetVideoPlayerListener(VideoPlayerListener* listener) 261a3e0fd82Sopenharmony_ci{ 262a3e0fd82Sopenharmony_ci videoPlayerListener_ = listener; 263a3e0fd82Sopenharmony_ci 264a3e0fd82Sopenharmony_ci if (playerListener_ != nullptr) { 265a3e0fd82Sopenharmony_ci playerListener_->SetVideoPlayerListerner(videoPlayerListener_); 266a3e0fd82Sopenharmony_ci } 267a3e0fd82Sopenharmony_ci} 268a3e0fd82Sopenharmony_ci 269a3e0fd82Sopenharmony_cibool UIVideo::Reset() 270a3e0fd82Sopenharmony_ci{ 271a3e0fd82Sopenharmony_ci if (videoPlayer_ != nullptr) { 272a3e0fd82Sopenharmony_ci if (sliderAnimator_ != nullptr) { 273a3e0fd82Sopenharmony_ci sliderAnimator_->Stop(); 274a3e0fd82Sopenharmony_ci } 275a3e0fd82Sopenharmony_ci if (playSlider_ != nullptr) { 276a3e0fd82Sopenharmony_ci playSlider_->SetValue(0); 277a3e0fd82Sopenharmony_ci } 278a3e0fd82Sopenharmony_ci if (currentTimeLabel_ != nullptr) { 279a3e0fd82Sopenharmony_ci currentTimeLabel_->SetText("00:00"); 280a3e0fd82Sopenharmony_ci } 281a3e0fd82Sopenharmony_ci if (totalTimeLabel_ != nullptr) { 282a3e0fd82Sopenharmony_ci totalTimeLabel_->SetText("00:00"); 283a3e0fd82Sopenharmony_ci } 284a3e0fd82Sopenharmony_ci if (pauseButton_ != nullptr) { 285a3e0fd82Sopenharmony_ci pauseButton_->SetVisible(true); 286a3e0fd82Sopenharmony_ci } 287a3e0fd82Sopenharmony_ci if (playButton_ != nullptr) { 288a3e0fd82Sopenharmony_ci playButton_->SetState(false); 289a3e0fd82Sopenharmony_ci } 290a3e0fd82Sopenharmony_ci int32_t ret = videoPlayer_->Reset(); 291a3e0fd82Sopenharmony_ci if (ret == 0) { 292a3e0fd82Sopenharmony_ci videoPlayer_->Release(); 293a3e0fd82Sopenharmony_ci return true; 294a3e0fd82Sopenharmony_ci } 295a3e0fd82Sopenharmony_ci } 296a3e0fd82Sopenharmony_ci return false; 297a3e0fd82Sopenharmony_ci} 298a3e0fd82Sopenharmony_ci 299a3e0fd82Sopenharmony_cibool UIVideo::EnableSingleLooping(bool loop) 300a3e0fd82Sopenharmony_ci{ 301a3e0fd82Sopenharmony_ci if (videoPlayer_ != nullptr) { 302a3e0fd82Sopenharmony_ci int32_t ret = videoPlayer_->EnableSingleLooping(loop); 303a3e0fd82Sopenharmony_ci if (ret == 0) { 304a3e0fd82Sopenharmony_ci return true; 305a3e0fd82Sopenharmony_ci } 306a3e0fd82Sopenharmony_ci } 307a3e0fd82Sopenharmony_ci return false; 308a3e0fd82Sopenharmony_ci} 309a3e0fd82Sopenharmony_ci 310a3e0fd82Sopenharmony_civoid UIVideo::ShowController(bool show) 311a3e0fd82Sopenharmony_ci{ 312a3e0fd82Sopenharmony_ci if (controllerGroup_ != nullptr) { 313a3e0fd82Sopenharmony_ci if (controllerGroup_->IsVisible() != show) { 314a3e0fd82Sopenharmony_ci controllerGroup_->SetVisible(show); 315a3e0fd82Sopenharmony_ci Invalidate(); 316a3e0fd82Sopenharmony_ci } 317a3e0fd82Sopenharmony_ci } 318a3e0fd82Sopenharmony_ci} 319a3e0fd82Sopenharmony_ci 320a3e0fd82Sopenharmony_civoid UIVideo::InitVideo() 321a3e0fd82Sopenharmony_ci{ 322a3e0fd82Sopenharmony_ci if (videoPlayer_ == nullptr) { 323a3e0fd82Sopenharmony_ci videoPlayer_ = std::make_shared<Player>(); 324a3e0fd82Sopenharmony_ci } 325a3e0fd82Sopenharmony_ci 326a3e0fd82Sopenharmony_ci InitControllerLabel(); 327a3e0fd82Sopenharmony_ci InitControllerButton(); 328a3e0fd82Sopenharmony_ci InitControllerSlider(); 329a3e0fd82Sopenharmony_ci 330a3e0fd82Sopenharmony_ci if (surfaceView_ == nullptr) { 331a3e0fd82Sopenharmony_ci surfaceView_ = new UISurfaceView(); 332a3e0fd82Sopenharmony_ci if (surfaceView_ == nullptr) { 333a3e0fd82Sopenharmony_ci GRAPHIC_LOGE("new UISurfaceView fail"); 334a3e0fd82Sopenharmony_ci return; 335a3e0fd82Sopenharmony_ci } 336a3e0fd82Sopenharmony_ci surfaceView_->SetPosition(0, 0); 337a3e0fd82Sopenharmony_ci surfaceView_->SetWidth(DEFAULT_VIEW_WIDTH); 338a3e0fd82Sopenharmony_ci surfaceView_->SetHeight(DEFAULT_VIEW_HEIGHT); 339a3e0fd82Sopenharmony_ci Add(surfaceView_); 340a3e0fd82Sopenharmony_ci } 341a3e0fd82Sopenharmony_ci if (controllerGroup_ == nullptr) { 342a3e0fd82Sopenharmony_ci controllerGroup_ = new UIViewGroup(); 343a3e0fd82Sopenharmony_ci if (controllerGroup_ == nullptr) { 344a3e0fd82Sopenharmony_ci GRAPHIC_LOGE("new UIViewGroup fail"); 345a3e0fd82Sopenharmony_ci return; 346a3e0fd82Sopenharmony_ci } 347a3e0fd82Sopenharmony_ci controllerGroup_->SetPosition(0, 0, DEFAULT_VIEW_WIDTH, DEFAULT_VIEW_HEIGHT); 348a3e0fd82Sopenharmony_ci controllerGroup_->SetStyle(STYLE_BACKGROUND_OPA, 0); 349a3e0fd82Sopenharmony_ci controllerGroup_->Add(titleLabel_); 350a3e0fd82Sopenharmony_ci controllerGroup_->Add(totalTimeLabel_); 351a3e0fd82Sopenharmony_ci controllerGroup_->Add(currentTimeLabel_); 352a3e0fd82Sopenharmony_ci controllerGroup_->Add(playSlider_); 353a3e0fd82Sopenharmony_ci controllerGroup_->Add(volumeButton_); 354a3e0fd82Sopenharmony_ci controllerGroup_->Add(playButton_); 355a3e0fd82Sopenharmony_ci controllerGroup_->Add(pauseButton_); 356a3e0fd82Sopenharmony_ci Add(controllerGroup_); 357a3e0fd82Sopenharmony_ci } 358a3e0fd82Sopenharmony_ci if (sliderAnimatorCallback_ == nullptr) { 359a3e0fd82Sopenharmony_ci sliderAnimatorCallback_ = new SliderAnimatorCallback(this, playSlider_, currentTimeLabel_); 360a3e0fd82Sopenharmony_ci if (sliderAnimatorCallback_ == nullptr) { 361a3e0fd82Sopenharmony_ci GRAPHIC_LOGE("new SliderAnimatorCallback fail"); 362a3e0fd82Sopenharmony_ci return; 363a3e0fd82Sopenharmony_ci } 364a3e0fd82Sopenharmony_ci sliderAnimatorCallback_->SetPlayButton(playButton_); 365a3e0fd82Sopenharmony_ci } 366a3e0fd82Sopenharmony_ci if (sliderAnimator_ == nullptr) { 367a3e0fd82Sopenharmony_ci sliderAnimator_ = new Animator(sliderAnimatorCallback_, this, 0, true); 368a3e0fd82Sopenharmony_ci if (sliderAnimator_ == nullptr) { 369a3e0fd82Sopenharmony_ci GRAPHIC_LOGE("new Animator fail"); 370a3e0fd82Sopenharmony_ci return; 371a3e0fd82Sopenharmony_ci } 372a3e0fd82Sopenharmony_ci sliderAnimatorCallback_->SetSliderAnimator(sliderAnimator_); 373a3e0fd82Sopenharmony_ci } 374a3e0fd82Sopenharmony_ci} 375a3e0fd82Sopenharmony_ci 376a3e0fd82Sopenharmony_civoid UIVideo::InitControllerLabel() 377a3e0fd82Sopenharmony_ci{ 378a3e0fd82Sopenharmony_ci if (titleLabel_ == nullptr) { 379a3e0fd82Sopenharmony_ci titleLabel_ = new UILabel(); 380a3e0fd82Sopenharmony_ci if (titleLabel_ == nullptr) { 381a3e0fd82Sopenharmony_ci GRAPHIC_LOGE("new UILabel fail"); 382a3e0fd82Sopenharmony_ci return; 383a3e0fd82Sopenharmony_ci } 384a3e0fd82Sopenharmony_ci titleLabel_->SetPosition(322, 28, 316, 29); // 322:pos x, 28:pos y, 316:width, 29:height 385a3e0fd82Sopenharmony_ci titleLabel_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, 386a3e0fd82Sopenharmony_ci UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); 387a3e0fd82Sopenharmony_ci titleLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20); // 20:font size 388a3e0fd82Sopenharmony_ci titleLabel_->SetText("title title"); 389a3e0fd82Sopenharmony_ci titleLabel_->SetTextColor(Color::White()); 390a3e0fd82Sopenharmony_ci } 391a3e0fd82Sopenharmony_ci 392a3e0fd82Sopenharmony_ci if (totalTimeLabel_ == nullptr) { 393a3e0fd82Sopenharmony_ci totalTimeLabel_ = new UILabel(); 394a3e0fd82Sopenharmony_ci if (totalTimeLabel_ == nullptr) { 395a3e0fd82Sopenharmony_ci GRAPHIC_LOGE("new UILabel fail"); 396a3e0fd82Sopenharmony_ci return; 397a3e0fd82Sopenharmony_ci } 398a3e0fd82Sopenharmony_ci // 580:pos x, 56:pos y offset 399a3e0fd82Sopenharmony_ci totalTimeLabel_->SetPosition(580, DEFAULT_VIEW_HEIGHT - 56, TIME_LABEL_WIDTH, TIME_LABEL_HEIGHT); 400a3e0fd82Sopenharmony_ci totalTimeLabel_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_RIGHT, 401a3e0fd82Sopenharmony_ci UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); 402a3e0fd82Sopenharmony_ci totalTimeLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); 403a3e0fd82Sopenharmony_ci totalTimeLabel_->SetTextColor(Color::White()); 404a3e0fd82Sopenharmony_ci totalTimeLabel_->SetText("00:00:00"); 405a3e0fd82Sopenharmony_ci } 406a3e0fd82Sopenharmony_ci 407a3e0fd82Sopenharmony_ci if (currentTimeLabel_ == nullptr) { 408a3e0fd82Sopenharmony_ci currentTimeLabel_ = new UILabel(); 409a3e0fd82Sopenharmony_ci if (currentTimeLabel_ == nullptr) { 410a3e0fd82Sopenharmony_ci GRAPHIC_LOGE("new UILabel fail"); 411a3e0fd82Sopenharmony_ci return; 412a3e0fd82Sopenharmony_ci } 413a3e0fd82Sopenharmony_ci // 80:pos x, 56:pos y offset 414a3e0fd82Sopenharmony_ci currentTimeLabel_->SetPosition(80, DEFAULT_VIEW_HEIGHT - 56, TIME_LABEL_WIDTH, TIME_LABEL_HEIGHT); 415a3e0fd82Sopenharmony_ci currentTimeLabel_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT, 416a3e0fd82Sopenharmony_ci UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); 417a3e0fd82Sopenharmony_ci currentTimeLabel_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full); 418a3e0fd82Sopenharmony_ci currentTimeLabel_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); 419a3e0fd82Sopenharmony_ci currentTimeLabel_->SetText("00:00:00"); 420a3e0fd82Sopenharmony_ci currentTimeLabel_->SetTextColor(Color::White()); 421a3e0fd82Sopenharmony_ci } 422a3e0fd82Sopenharmony_ci} 423a3e0fd82Sopenharmony_ci 424a3e0fd82Sopenharmony_civoid UIVideo::InitControllerButton() 425a3e0fd82Sopenharmony_ci{ 426a3e0fd82Sopenharmony_ci if (playButton_ == nullptr) { 427a3e0fd82Sopenharmony_ci playButton_ = new UIToggleButton(); 428a3e0fd82Sopenharmony_ci if (playButton_ == nullptr) { 429a3e0fd82Sopenharmony_ci GRAPHIC_LOGE("new UIToggleButton fail"); 430a3e0fd82Sopenharmony_ci return; 431a3e0fd82Sopenharmony_ci } 432a3e0fd82Sopenharmony_ci // 24:pox x, 88:pos y offset 433a3e0fd82Sopenharmony_ci playButton_->SetPosition(24, DEFAULT_VIEW_HEIGHT - 88, TOGGLE_BUTTON_WIDTH, TOGGLE_BUTTON_HEIGHT); 434a3e0fd82Sopenharmony_ci playButton_->SetImages(MEDIA_IMAGE_PAUSE, MEDIA_IMAGE_PLAY); 435a3e0fd82Sopenharmony_ci playButton_->SetState(true); 436a3e0fd82Sopenharmony_ci playButton_->SetOnClickListener(this); 437a3e0fd82Sopenharmony_ci } 438a3e0fd82Sopenharmony_ci 439a3e0fd82Sopenharmony_ci if (pauseButton_ == nullptr) { 440a3e0fd82Sopenharmony_ci pauseButton_ = new UIToggleButton(); 441a3e0fd82Sopenharmony_ci if (pauseButton_ == nullptr) { 442a3e0fd82Sopenharmony_ci GRAPHIC_LOGE("new UIToggleButton fail"); 443a3e0fd82Sopenharmony_ci return; 444a3e0fd82Sopenharmony_ci } 445a3e0fd82Sopenharmony_ci // 448:pox x, 208:pos y 2:double width 2:double height 446a3e0fd82Sopenharmony_ci pauseButton_->SetPosition(448, 208, 2 * TOGGLE_BUTTON_WIDTH, 2 * TOGGLE_BUTTON_HEIGHT); 447a3e0fd82Sopenharmony_ci pauseButton_->SetImages(MEDIA_IMAGE_PLAY_CENTER, MEDIA_IMAGE_PLAY_CENTER); 448a3e0fd82Sopenharmony_ci pauseButton_->SetVisible(false); 449a3e0fd82Sopenharmony_ci pauseButton_->SetOnClickListener(this); 450a3e0fd82Sopenharmony_ci } 451a3e0fd82Sopenharmony_ci 452a3e0fd82Sopenharmony_ci if (volumeButton_ == nullptr) { 453a3e0fd82Sopenharmony_ci volumeButton_ = new UIToggleButton(); 454a3e0fd82Sopenharmony_ci if (volumeButton_ == nullptr) { 455a3e0fd82Sopenharmony_ci GRAPHIC_LOGE("new UIToggleButton fail"); 456a3e0fd82Sopenharmony_ci return; 457a3e0fd82Sopenharmony_ci } 458a3e0fd82Sopenharmony_ci // 56:pox x offset, 88:pos y offset 459a3e0fd82Sopenharmony_ci volumeButton_->SetPosition(DEFAULT_VIEW_WIDTH - 56, DEFAULT_VIEW_HEIGHT - 88, TOGGLE_BUTTON_WIDTH, 460a3e0fd82Sopenharmony_ci TOGGLE_BUTTON_HEIGHT); 461a3e0fd82Sopenharmony_ci volumeButton_->SetImages(MEDIA_IMAGE_MUTE, MEDIA_IMAGE_VOLUME); 462a3e0fd82Sopenharmony_ci volumeButton_->SetOnClickListener(this); 463a3e0fd82Sopenharmony_ci } 464a3e0fd82Sopenharmony_ci} 465a3e0fd82Sopenharmony_ci 466a3e0fd82Sopenharmony_civoid UIVideo::OnVideoComplete() 467a3e0fd82Sopenharmony_ci{ 468a3e0fd82Sopenharmony_ci if (videoPlayer_ != nullptr) { 469a3e0fd82Sopenharmony_ci videoPlayer_->Stop(); 470a3e0fd82Sopenharmony_ci completeFlag_ = true; 471a3e0fd82Sopenharmony_ci 472a3e0fd82Sopenharmony_ci if (sliderAnimator_ != nullptr) { 473a3e0fd82Sopenharmony_ci sliderAnimator_->Stop(); 474a3e0fd82Sopenharmony_ci } 475a3e0fd82Sopenharmony_ci if (playSlider_ != nullptr) { 476a3e0fd82Sopenharmony_ci playSlider_->SetValue(playSlider_->GetRangeMax()); 477a3e0fd82Sopenharmony_ci } 478a3e0fd82Sopenharmony_ci if (playButton_ != nullptr) { 479a3e0fd82Sopenharmony_ci playButton_->SetState(false); 480a3e0fd82Sopenharmony_ci } 481a3e0fd82Sopenharmony_ci if (pauseButton_ != nullptr) { 482a3e0fd82Sopenharmony_ci pauseButton_->SetVisible(true); 483a3e0fd82Sopenharmony_ci } 484a3e0fd82Sopenharmony_ci if (controllerGroup_ != nullptr) { 485a3e0fd82Sopenharmony_ci controllerGroup_->SetVisible(true); 486a3e0fd82Sopenharmony_ci } 487a3e0fd82Sopenharmony_ci Invalidate(); 488a3e0fd82Sopenharmony_ci } 489a3e0fd82Sopenharmony_ci} 490a3e0fd82Sopenharmony_ci 491a3e0fd82Sopenharmony_civoid UIVideo::InitControllerSlider() 492a3e0fd82Sopenharmony_ci{ 493a3e0fd82Sopenharmony_ci if (playSlider_ == nullptr) { 494a3e0fd82Sopenharmony_ci playSlider_ = new UISlider(); 495a3e0fd82Sopenharmony_ci if (playSlider_ == nullptr) { 496a3e0fd82Sopenharmony_ci GRAPHIC_LOGE("new UISlider fail"); 497a3e0fd82Sopenharmony_ci return; 498a3e0fd82Sopenharmony_ci } 499a3e0fd82Sopenharmony_ci // 80:pos x, 74:width offset, 5:multiply, 6:divide, 4:height 500a3e0fd82Sopenharmony_ci playSlider_->SetPosition(80, DEFAULT_VIEW_HEIGHT - 74, DEFAULT_VIEW_WIDTH * 5 / 6, 4); 501a3e0fd82Sopenharmony_ci playSlider_->SetValidHeight(4); // 4:height 502a3e0fd82Sopenharmony_ci playSlider_->SetValidWidth(DEFAULT_VIEW_WIDTH * 5 / 6); // 5:multiply, 6:divide 503a3e0fd82Sopenharmony_ci playSlider_->SetRange(100, 0); // 100:range max 504a3e0fd82Sopenharmony_ci playSlider_->SetValue(0); 505a3e0fd82Sopenharmony_ci playSlider_->SetKnobWidth(KNOB_WIDTH); 506a3e0fd82Sopenharmony_ci playSlider_->SetSliderRadius(5, 5); // 5:background radius, 5:foreground radius 507a3e0fd82Sopenharmony_ci playSlider_->SetKnobRadius(KNOB_WIDTH / 2); // 2:half 508a3e0fd82Sopenharmony_ci playSlider_->SetKnobStyle(STYLE_BACKGROUND_COLOR, Color::White().full); 509a3e0fd82Sopenharmony_ci playSlider_->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, 0x1A888888); // 0x1A888888:slider background color 510a3e0fd82Sopenharmony_ci playSlider_->SetBackgroundStyle(STYLE_BACKGROUND_OPA, 90); // 90:background opa 511a3e0fd82Sopenharmony_ci playSlider_->SetDirection(UISlider::Direction::DIR_LEFT_TO_RIGHT); 512a3e0fd82Sopenharmony_ci playSlider_->SetSliderEventListener(this); 513a3e0fd82Sopenharmony_ci } 514a3e0fd82Sopenharmony_ci} 515a3e0fd82Sopenharmony_ci 516a3e0fd82Sopenharmony_civoid UIVideo::DeleteController() 517a3e0fd82Sopenharmony_ci{ 518a3e0fd82Sopenharmony_ci if (controllerGroup_ != nullptr) { 519a3e0fd82Sopenharmony_ci controllerGroup_->RemoveAll(); 520a3e0fd82Sopenharmony_ci Remove(controllerGroup_); 521a3e0fd82Sopenharmony_ci delete controllerGroup_; 522a3e0fd82Sopenharmony_ci controllerGroup_ = nullptr; 523a3e0fd82Sopenharmony_ci } 524a3e0fd82Sopenharmony_ci if (playButton_ != nullptr) { 525a3e0fd82Sopenharmony_ci delete playButton_; 526a3e0fd82Sopenharmony_ci playButton_ = nullptr; 527a3e0fd82Sopenharmony_ci } 528a3e0fd82Sopenharmony_ci if (pauseButton_ != nullptr) { 529a3e0fd82Sopenharmony_ci delete pauseButton_; 530a3e0fd82Sopenharmony_ci pauseButton_ = nullptr; 531a3e0fd82Sopenharmony_ci } 532a3e0fd82Sopenharmony_ci if (volumeButton_ != nullptr) { 533a3e0fd82Sopenharmony_ci delete volumeButton_; 534a3e0fd82Sopenharmony_ci volumeButton_ = nullptr; 535a3e0fd82Sopenharmony_ci } 536a3e0fd82Sopenharmony_ci if (playSlider_ != nullptr) { 537a3e0fd82Sopenharmony_ci delete playSlider_; 538a3e0fd82Sopenharmony_ci playSlider_ = nullptr; 539a3e0fd82Sopenharmony_ci } 540a3e0fd82Sopenharmony_ci if (sliderAnimatorCallback_ != nullptr) { 541a3e0fd82Sopenharmony_ci delete sliderAnimatorCallback_; 542a3e0fd82Sopenharmony_ci sliderAnimatorCallback_ = nullptr; 543a3e0fd82Sopenharmony_ci } 544a3e0fd82Sopenharmony_ci if (titleLabel_ != nullptr) { 545a3e0fd82Sopenharmony_ci delete titleLabel_; 546a3e0fd82Sopenharmony_ci titleLabel_ = nullptr; 547a3e0fd82Sopenharmony_ci } 548a3e0fd82Sopenharmony_ci if (totalTimeLabel_ != nullptr) { 549a3e0fd82Sopenharmony_ci delete totalTimeLabel_; 550a3e0fd82Sopenharmony_ci totalTimeLabel_ = nullptr; 551a3e0fd82Sopenharmony_ci } 552a3e0fd82Sopenharmony_ci if (currentTimeLabel_ != nullptr) { 553a3e0fd82Sopenharmony_ci delete currentTimeLabel_; 554a3e0fd82Sopenharmony_ci currentTimeLabel_ = nullptr; 555a3e0fd82Sopenharmony_ci } 556a3e0fd82Sopenharmony_ci} 557a3e0fd82Sopenharmony_ci 558a3e0fd82Sopenharmony_cibool UIVideo::OnClick(UIView& view, const ClickEvent& event) 559a3e0fd82Sopenharmony_ci{ 560a3e0fd82Sopenharmony_ci if (videoPlayer_ == nullptr) { 561a3e0fd82Sopenharmony_ci return true; 562a3e0fd82Sopenharmony_ci } 563a3e0fd82Sopenharmony_ci if (&view == playButton_) { 564a3e0fd82Sopenharmony_ci if (completeFlag_) { 565a3e0fd82Sopenharmony_ci completeFlag_ = false; 566a3e0fd82Sopenharmony_ci if (pauseButton_ != nullptr) { 567a3e0fd82Sopenharmony_ci pauseButton_->SetVisible(true); 568a3e0fd82Sopenharmony_ci } 569a3e0fd82Sopenharmony_ci if (controllerGroup_ != nullptr) { 570a3e0fd82Sopenharmony_ci controllerGroup_->SetVisible(true); 571a3e0fd82Sopenharmony_ci } 572a3e0fd82Sopenharmony_ci return true; 573a3e0fd82Sopenharmony_ci } 574a3e0fd82Sopenharmony_ci 575a3e0fd82Sopenharmony_ci if ((sliderAnimatorCallback_ != nullptr) && (pauseButton_ != nullptr) && (playButton_ != nullptr)) { 576a3e0fd82Sopenharmony_ci sliderAnimatorCallback_->ResetTickTime(); 577a3e0fd82Sopenharmony_ci if (playButton_->GetState()) { 578a3e0fd82Sopenharmony_ci Play(); 579a3e0fd82Sopenharmony_ci pauseButton_->SetVisible(false); 580a3e0fd82Sopenharmony_ci } else { 581a3e0fd82Sopenharmony_ci Pause(); 582a3e0fd82Sopenharmony_ci pauseButton_->SetVisible(true); 583a3e0fd82Sopenharmony_ci } 584a3e0fd82Sopenharmony_ci pauseButton_->Invalidate(); 585a3e0fd82Sopenharmony_ci } 586a3e0fd82Sopenharmony_ci } else if (&view == pauseButton_) { 587a3e0fd82Sopenharmony_ci if ((pauseButton_ != nullptr) && pauseButton_->IsVisible()) { 588a3e0fd82Sopenharmony_ci pauseButton_->SetVisible(false); 589a3e0fd82Sopenharmony_ci Play(); 590a3e0fd82Sopenharmony_ci } 591a3e0fd82Sopenharmony_ci } else if (&view == volumeButton_) { 592a3e0fd82Sopenharmony_ci if ((volumeButton_ != nullptr) && volumeButton_->GetState()) { 593a3e0fd82Sopenharmony_ci videoPlayer_->SetVolume(0, 0); 594a3e0fd82Sopenharmony_ci } else { 595a3e0fd82Sopenharmony_ci SetVolume(leftVolumeValue_, rightVolumeValue_); 596a3e0fd82Sopenharmony_ci } 597a3e0fd82Sopenharmony_ci } 598a3e0fd82Sopenharmony_ci return true; 599a3e0fd82Sopenharmony_ci} 600a3e0fd82Sopenharmony_ci 601a3e0fd82Sopenharmony_cibool UIVideo::OnPress(UIView& view, const PressEvent& event) 602a3e0fd82Sopenharmony_ci{ 603a3e0fd82Sopenharmony_ci if (sliderAnimatorCallback_ != nullptr) { 604a3e0fd82Sopenharmony_ci sliderAnimatorCallback_->ResetTickTime(); 605a3e0fd82Sopenharmony_ci if (controllerGroup_ != nullptr) { 606a3e0fd82Sopenharmony_ci controllerGroup_->SetVisible(true); 607a3e0fd82Sopenharmony_ci } 608a3e0fd82Sopenharmony_ci Invalidate(); 609a3e0fd82Sopenharmony_ci } 610a3e0fd82Sopenharmony_ci return true; 611a3e0fd82Sopenharmony_ci} 612a3e0fd82Sopenharmony_ci 613a3e0fd82Sopenharmony_civoid UIVideo::OnChange(int32_t progress) 614a3e0fd82Sopenharmony_ci{ 615a3e0fd82Sopenharmony_ci if (videoPlayer_ != nullptr) { 616a3e0fd82Sopenharmony_ci if (sliderAnimatorCallback_ != nullptr) { 617a3e0fd82Sopenharmony_ci sliderAnimatorCallback_->ResetTickTime(); 618a3e0fd82Sopenharmony_ci } 619a3e0fd82Sopenharmony_ci int64_t currentValue = progress * duration_ / 100; // 100:percent 620a3e0fd82Sopenharmony_ci if (currentTimeLabel_ != nullptr) { 621a3e0fd82Sopenharmony_ci char timer[10] = {0}; // 10:timer length 622a3e0fd82Sopenharmony_ci if (!GetTimerFromMSecond(currentValue, timer, sizeof(timer))) { 623a3e0fd82Sopenharmony_ci return; 624a3e0fd82Sopenharmony_ci } 625a3e0fd82Sopenharmony_ci currentTimeLabel_->SetText(&timer[0]); 626a3e0fd82Sopenharmony_ci } 627a3e0fd82Sopenharmony_ci videoPlayer_->Rewind(currentValue, PLAYER_SEEK_PREVIOUS_SYNC); 628a3e0fd82Sopenharmony_ci } 629a3e0fd82Sopenharmony_ci} 630a3e0fd82Sopenharmony_ci 631a3e0fd82Sopenharmony_civoid UIVideo::SetSurfaceInfo() 632a3e0fd82Sopenharmony_ci{ 633a3e0fd82Sopenharmony_ci if (videoPlayer_ == nullptr) { 634a3e0fd82Sopenharmony_ci return; 635a3e0fd82Sopenharmony_ci } 636a3e0fd82Sopenharmony_ci int32_t width = 0; 637a3e0fd82Sopenharmony_ci int32_t height = 0; 638a3e0fd82Sopenharmony_ci videoPlayer_->GetVideoWidth(width); 639a3e0fd82Sopenharmony_ci videoPlayer_->GetVideoHeight(height); 640a3e0fd82Sopenharmony_ci 641a3e0fd82Sopenharmony_ci if ((width <= 0) || (height <= 0)) { 642a3e0fd82Sopenharmony_ci videoPlayer_->Reset(); 643a3e0fd82Sopenharmony_ci return; 644a3e0fd82Sopenharmony_ci } 645a3e0fd82Sopenharmony_ci 646a3e0fd82Sopenharmony_ci int16_t viewWidth = GetWidth(); 647a3e0fd82Sopenharmony_ci int16_t viewHeight = GetHeight(); 648a3e0fd82Sopenharmony_ci if ((viewWidth <= 0) || (viewHeight <= 0)) { 649a3e0fd82Sopenharmony_ci videoPlayer_->Reset(); 650a3e0fd82Sopenharmony_ci return; 651a3e0fd82Sopenharmony_ci } 652a3e0fd82Sopenharmony_ci float ratioX = static_cast<float>(width) / viewWidth; 653a3e0fd82Sopenharmony_ci float ratioY = static_cast<float>(height) / viewHeight; 654a3e0fd82Sopenharmony_ci uint16_t surfaceViewWidth; 655a3e0fd82Sopenharmony_ci uint16_t surfaceViewHeight; 656a3e0fd82Sopenharmony_ci uint16_t surfaceViewPositionX = 0; 657a3e0fd82Sopenharmony_ci uint16_t surfaceViewPositionY = 0; 658a3e0fd82Sopenharmony_ci if (ratioX > ratioY) { 659a3e0fd82Sopenharmony_ci surfaceViewWidth = viewWidth; 660a3e0fd82Sopenharmony_ci surfaceViewHeight = height / ratioX; 661a3e0fd82Sopenharmony_ci surfaceViewPositionY = (viewHeight - surfaceViewHeight) / 2; // 2:half 662a3e0fd82Sopenharmony_ci } else { 663a3e0fd82Sopenharmony_ci surfaceViewWidth = width / ratioY; 664a3e0fd82Sopenharmony_ci surfaceViewHeight = viewHeight; 665a3e0fd82Sopenharmony_ci surfaceViewPositionX = (viewWidth - surfaceViewWidth) / 2; // 2:half 666a3e0fd82Sopenharmony_ci } 667a3e0fd82Sopenharmony_ci if (surfaceView_ != nullptr) { 668a3e0fd82Sopenharmony_ci surfaceView_->SetPosition(surfaceViewPositionX, surfaceViewPositionY); 669a3e0fd82Sopenharmony_ci surfaceView_->SetWidth(surfaceViewWidth - 1); 670a3e0fd82Sopenharmony_ci surfaceView_->SetHeight(surfaceViewHeight); 671a3e0fd82Sopenharmony_ci videoPlayer_->SetVideoSurface(surfaceView_->GetSurface()); 672a3e0fd82Sopenharmony_ci } 673a3e0fd82Sopenharmony_ci} 674a3e0fd82Sopenharmony_ci 675a3e0fd82Sopenharmony_cibool UIVideo::GetTimerFromMSecond(int64_t currentTime, char* timer, int32_t len) 676a3e0fd82Sopenharmony_ci{ 677a3e0fd82Sopenharmony_ci int64_t currentSecond = currentTime / 1000; // 1000:millisecond 678a3e0fd82Sopenharmony_ci int32_t second = currentSecond % 60; // 60:second 679a3e0fd82Sopenharmony_ci int32_t minute = (currentSecond / 60) % 60; // 60:minute 60:second 680a3e0fd82Sopenharmony_ci int32_t hour = (currentSecond / 60) / 60; // 60:minute 60:second 681a3e0fd82Sopenharmony_ci int32_t ret = 0; 682a3e0fd82Sopenharmony_ci ret = sprintf_s(timer, len, "%02d:%02d:%02d", hour, minute, second); 683a3e0fd82Sopenharmony_ci if (ret < 0) { 684a3e0fd82Sopenharmony_ci return false; 685a3e0fd82Sopenharmony_ci } 686a3e0fd82Sopenharmony_ci return true; 687a3e0fd82Sopenharmony_ci} 688a3e0fd82Sopenharmony_ci 689a3e0fd82Sopenharmony_civoid UIVideo::SliderAnimatorCallback::Callback(UIView* view) 690a3e0fd82Sopenharmony_ci{ 691a3e0fd82Sopenharmony_ci if (video_ != nullptr) { 692a3e0fd82Sopenharmony_ci int64_t currentTime = 0; 693a3e0fd82Sopenharmony_ci video_->GetCurrentTime(currentTime); 694a3e0fd82Sopenharmony_ci if (timeLabel_ != nullptr) { 695a3e0fd82Sopenharmony_ci char timer[10] = {0}; // 10:timer length 696a3e0fd82Sopenharmony_ci if (!video_->GetTimerFromMSecond(currentTime, timer, sizeof(timer))) { 697a3e0fd82Sopenharmony_ci return; 698a3e0fd82Sopenharmony_ci } 699a3e0fd82Sopenharmony_ci timeLabel_->SetText(&timer[0]); 700a3e0fd82Sopenharmony_ci timeLabel_->Invalidate(); 701a3e0fd82Sopenharmony_ci } 702a3e0fd82Sopenharmony_ci if (slider_ != nullptr) { 703a3e0fd82Sopenharmony_ci int64_t curPosition = currentTime * slider_->GetRangeMax() / duration_; 704a3e0fd82Sopenharmony_ci slider_->SetValue(curPosition); 705a3e0fd82Sopenharmony_ci slider_->Invalidate(); 706a3e0fd82Sopenharmony_ci } 707a3e0fd82Sopenharmony_ci 708a3e0fd82Sopenharmony_ci uint32_t runTime = 0; 709a3e0fd82Sopenharmony_ci if (sliderAnimator_ != nullptr) { 710a3e0fd82Sopenharmony_ci runTime = sliderAnimator_->GetRunTime(); 711a3e0fd82Sopenharmony_ci } 712a3e0fd82Sopenharmony_ci if ((runTime > tickCount_) && (runTime - tickCount_ >= HIDE_MILLI_SECOND)) { 713a3e0fd82Sopenharmony_ci video_->ShowController(false); 714a3e0fd82Sopenharmony_ci tickCount_ = runTime; 715a3e0fd82Sopenharmony_ci } 716a3e0fd82Sopenharmony_ci } 717a3e0fd82Sopenharmony_ci} 718a3e0fd82Sopenharmony_ci} // namespace OHOS 719a3e0fd82Sopenharmony_ci 720a3e0fd82Sopenharmony_ci#endif // VERSION_LITE 721