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 #include "ohos_adapter/bridge/ark_media_avsession_adapter_impl.h" 17 18 #include "ohos_adapter/bridge/ark_media_avsession_callback_adapter_wrapper.h" 19 #include "ohos_adapter/bridge/ark_media_avsession_metadata_adapter_wrapper.h" 20 #include "ohos_adapter/bridge/ark_media_avsession_position_adapter_wrapper.h" 21 22 #include "base/bridge/ark_web_bridge_macros.h" 23 24 namespace OHOS::ArkWeb { 25 ArkMediaAVSessionAdapterImpl(std::shared_ptr<OHOS::NWeb::MediaAVSessionAdapter> ref)26ArkMediaAVSessionAdapterImpl::ArkMediaAVSessionAdapterImpl(std::shared_ptr<OHOS::NWeb::MediaAVSessionAdapter> ref) 27 : real_(ref) 28 {} 29 CreateAVSession(int32_t type)30bool ArkMediaAVSessionAdapterImpl::CreateAVSession(int32_t type) 31 { 32 return real_->CreateAVSession((OHOS::NWeb::MediaAVSessionType)type); 33 } 34 DestroyAVSession()35void ArkMediaAVSessionAdapterImpl::DestroyAVSession() 36 { 37 real_->DestroyAVSession(); 38 } 39 RegistCallback(ArkWebRefPtr<ArkMediaAVSessionCallbackAdapter> callbackAdapter)40bool ArkMediaAVSessionAdapterImpl::RegistCallback(ArkWebRefPtr<ArkMediaAVSessionCallbackAdapter> callbackAdapter) 41 { 42 if (!(CHECK_REF_PTR_IS_NULL(callbackAdapter))) { 43 return real_->RegistCallback(std::make_shared<ArkMediaAVSessionCallbackAdapterWrapper>(callbackAdapter)); 44 } 45 return false; 46 } 47 IsActivated()48bool ArkMediaAVSessionAdapterImpl::IsActivated() 49 { 50 return real_->IsActivated(); 51 } 52 Activate()53bool ArkMediaAVSessionAdapterImpl::Activate() 54 { 55 return real_->Activate(); 56 } 57 DeActivate()58void ArkMediaAVSessionAdapterImpl::DeActivate() 59 { 60 real_->DeActivate(); 61 } 62 SetMetadata(const ArkWebRefPtr<ArkMediaAVSessionMetadataAdapter> metadata)63void ArkMediaAVSessionAdapterImpl::SetMetadata(const ArkWebRefPtr<ArkMediaAVSessionMetadataAdapter> metadata) 64 { 65 if (CHECK_REF_PTR_IS_NULL(metadata)) { 66 real_->SetMetadata(nullptr); 67 } else { 68 real_->SetMetadata(std::make_shared<ArkMediaAVSessionMetadataAdapterWrapper>(metadata)); 69 } 70 } 71 SetPlaybackState(int32_t state)72void ArkMediaAVSessionAdapterImpl::SetPlaybackState(int32_t state) 73 { 74 real_->SetPlaybackState((OHOS::NWeb::MediaAVSessionPlayState)state); 75 } 76 SetPlaybackPosition(const ArkWebRefPtr<ArkMediaAVSessionPositionAdapter> position)77void ArkMediaAVSessionAdapterImpl::SetPlaybackPosition(const ArkWebRefPtr<ArkMediaAVSessionPositionAdapter> position) 78 { 79 if (CHECK_REF_PTR_IS_NULL(position)) { 80 real_->SetPlaybackPosition(nullptr); 81 } else { 82 real_->SetPlaybackPosition(std::make_shared<ArkMediaAVSessionPositionAdapterWrapper>(position)); 83 } 84 } 85 86 } // namespace OHOS::ArkWeb 87