1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FRAMEWORKS_BOOTANIMATION_INCLUDE_BOOT_PLAYER_H 17 #define FRAMEWORKS_BOOTANIMATION_INCLUDE_BOOT_PLAYER_H 18 19 #ifdef PLAYER_FRAMEWORK_ENABLE 20 #include "player.h" 21 #endif 22 #include "transaction/rs_interfaces.h" 23 #include "util.h" 24 25 namespace OHOS { 26 static const int64_t MAX_WAIT_MEDIA_CREATE_TIME = 5000; // 5S 27 #ifdef PLAYER_FRAMEWORK_ENABLE 28 static const int CONTENT_TYPE_UNKNOWN = 0; 29 static const int STREAM_USAGE_ENFORCED_TONE = 15; 30 #endif 31 32 class BootPlayer { 33 public: ~BootPlayer()34 virtual ~BootPlayer() {}; 35 Play()36 virtual void Play() {}; 37 GetResPath(const std::string & type)38 std::string GetResPath(const std::string& type) 39 { 40 if (IsFileExisted(resPath_)) { 41 return FILE_PREFIX + resPath_; 42 } 43 return type == TYPE_VIDEO ? BOOT_VIDEO_PATH : BOOT_SOUND_PATH; 44 } 45 46 #ifdef PLAYER_FRAMEWORK_ENABLE SetCustomizedVolume(const int volume)47 bool SetCustomizedVolume(const int volume) 48 { 49 if (mediaPlayer_ == nullptr) { 50 LOGE("mediaPlayer is nullptr."); 51 return false; 52 } 53 float customizedVolume = (float)volume/MAX_VOLUME; 54 LOGE("customizedVolume: %{public}d -> %{public}f", volume, customizedVolume); 55 int ret = mediaPlayer_->SetVolume(customizedVolume, customizedVolume); 56 if (ret != 0) { 57 LOGE("PlayVideo SetVolume fail, errorCode:%{public}d", ret); 58 return false; 59 } 60 return true; 61 } 62 buildMediaFormat()63 Media::Format buildMediaFormat() 64 { 65 Media::Format format; 66 format.PutIntValue(Media::PlayerKeys::CONTENT_TYPE, CONTENT_TYPE_UNKNOWN); 67 format.PutIntValue(Media::PlayerKeys::STREAM_USAGE, STREAM_USAGE_ENFORCED_TONE); 68 format.PutIntValue(Media::PlayerKeys::RENDERER_FLAG, 0); 69 return format; 70 } 71 #endif 72 73 Rosen::ScreenId screenId_; 74 std::string resPath_; 75 bool isSoundEnabled_ = false; 76 std::shared_ptr<Media::Player> mediaPlayer_; 77 }; 78 } // namespace OHOS 79 80 #endif // FRAMEWORKS_BOOTANIMATION_INCLUDE_BOOT_PLAYER_H 81