1 /*
2  * Copyright (c) 2023 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_player_adapter_impl.h"
17 
18 #include "ohos_adapter/bridge/ark_iconsumer_surface_adapter_impl.h"
19 #include "ohos_adapter/bridge/ark_player_callback_adapter_wrapper.h"
20 
21 #include "base/bridge/ark_web_bridge_macros.h"
22 
23 namespace OHOS::ArkWeb {
24 
ArkPlayerAdapterImpl(std::shared_ptr<OHOS::NWeb::PlayerAdapter> ref)25 ArkPlayerAdapterImpl::ArkPlayerAdapterImpl(std::shared_ptr<OHOS::NWeb::PlayerAdapter> ref) : real_(ref) {}
26 
SetPlayerCallback(ArkWebRefPtr<ArkPlayerCallbackAdapter> callbackAdapter)27 int32_t ArkPlayerAdapterImpl::SetPlayerCallback(ArkWebRefPtr<ArkPlayerCallbackAdapter> callbackAdapter)
28 {
29     if (CHECK_REF_PTR_IS_NULL(callbackAdapter)) {
30         return real_->SetPlayerCallback(nullptr);
31     }
32 
33     return real_->SetPlayerCallback(std::make_shared<ArkPlayerCallbackAdapterWrapper>(callbackAdapter));
34 }
35 
SetSource(const ArkWebString & url)36 int32_t ArkPlayerAdapterImpl::SetSource(const ArkWebString& url)
37 {
38     std::string surl = ArkWebStringStructToClass(url);
39     return real_->SetSource(surl);
40 }
41 
SetSource(int32_t fd,int64_t offset,int64_t size)42 int32_t ArkPlayerAdapterImpl::SetSource(int32_t fd, int64_t offset, int64_t size)
43 {
44     return real_->SetSource(fd, offset, size);
45 }
46 
SetVideoSurface(ArkWebRefPtr<ArkIConsumerSurfaceAdapter> cSurfaceAdapter)47 int32_t ArkPlayerAdapterImpl::SetVideoSurface(ArkWebRefPtr<ArkIConsumerSurfaceAdapter> cSurfaceAdapter)
48 {
49     ArkIConsumerSurfaceAdapterImpl* imp = static_cast<ArkIConsumerSurfaceAdapterImpl*>(cSurfaceAdapter.get());
50     return real_->SetVideoSurface(imp->real_);
51 }
52 
SetVolume(float leftVolume,float rightVolume)53 int32_t ArkPlayerAdapterImpl::SetVolume(float leftVolume, float rightVolume)
54 {
55     return real_->SetVolume(leftVolume, rightVolume);
56 }
57 
Seek(int32_t mSeconds,int32_t mode)58 int32_t ArkPlayerAdapterImpl::Seek(int32_t mSeconds, int32_t mode)
59 {
60     return real_->Seek(mSeconds, (OHOS::NWeb::PlayerSeekMode)mode);
61 }
62 
Play()63 int32_t ArkPlayerAdapterImpl::Play()
64 {
65     return real_->Play();
66 }
67 
Pause()68 int32_t ArkPlayerAdapterImpl::Pause()
69 {
70     return real_->Pause();
71 }
72 
PrepareAsync()73 int32_t ArkPlayerAdapterImpl::PrepareAsync()
74 {
75     return real_->PrepareAsync();
76 }
77 
GetCurrentTime(int32_t & currentTime)78 int32_t ArkPlayerAdapterImpl::GetCurrentTime(int32_t& currentTime)
79 {
80     return real_->GetCurrentTime(currentTime);
81 }
82 
GetDuration(int32_t & duration)83 int32_t ArkPlayerAdapterImpl::GetDuration(int32_t& duration)
84 {
85     return real_->GetDuration(duration);
86 }
87 
SetPlaybackSpeed(int32_t mode)88 int32_t ArkPlayerAdapterImpl::SetPlaybackSpeed(int32_t mode)
89 {
90     return real_->SetPlaybackSpeed((OHOS::NWeb::PlaybackRateMode)mode);
91 }
92 
93 } // namespace OHOS::ArkWeb
94