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_wrapper.h"
17
18 #include "ohos_adapter/bridge/ark_iconsumer_surface_adapter_wrapper.h"
19 #include "ohos_adapter/bridge/ark_player_callback_adapter_impl.h"
20
21 #include "base/bridge/ark_web_bridge_macros.h"
22
23 namespace OHOS::ArkWeb {
24
ArkPlayerAdapterWrapper(ArkWebRefPtr<ArkPlayerAdapter> ref)25 ArkPlayerAdapterWrapper::ArkPlayerAdapterWrapper(ArkWebRefPtr<ArkPlayerAdapter> ref) : ctocpp_(ref) {}
26
SetPlayerCallback(std::shared_ptr<OHOS::NWeb::PlayerCallbackAdapter> callbackAdapter)27 int32_t ArkPlayerAdapterWrapper::SetPlayerCallback(std::shared_ptr<OHOS::NWeb::PlayerCallbackAdapter> callbackAdapter)
28 {
29 if (CHECK_SHARED_PTR_IS_NULL(callbackAdapter)) {
30 return ctocpp_->SetPlayerCallback(nullptr);
31 }
32
33 return ctocpp_->SetPlayerCallback(new ArkPlayerCallbackAdapterImpl(callbackAdapter));
34 }
35
SetSource(const std::string & url)36 int32_t ArkPlayerAdapterWrapper::SetSource(const std::string& url)
37 {
38 ArkWebString str = ArkWebStringClassToStruct(url);
39 return ctocpp_->SetSource(str);
40 }
41
SetSource(int32_t fd,int64_t offset,int64_t size)42 int32_t ArkPlayerAdapterWrapper::SetSource(int32_t fd, int64_t offset, int64_t size)
43 {
44 return ctocpp_->SetSource(fd, offset, size);
45 }
46
SetVideoSurface(std::shared_ptr<OHOS::NWeb::IConsumerSurfaceAdapter> cSurfaceAdapter)47 int32_t ArkPlayerAdapterWrapper::SetVideoSurface(std::shared_ptr<OHOS::NWeb::IConsumerSurfaceAdapter> cSurfaceAdapter)
48 {
49 std::shared_ptr<ArkIConsumerSurfaceAdapterWrapper> wrapper =
50 std::static_pointer_cast<ArkIConsumerSurfaceAdapterWrapper>(cSurfaceAdapter);
51 return ctocpp_->SetVideoSurface(wrapper->ctocpp_);
52 }
53
SetVolume(float leftVolume,float rightVolume)54 int32_t ArkPlayerAdapterWrapper::SetVolume(float leftVolume, float rightVolume)
55 {
56 return ctocpp_->SetVolume(leftVolume, rightVolume);
57 }
58
Seek(int32_t mSeconds,OHOS::NWeb::PlayerSeekMode mode)59 int32_t ArkPlayerAdapterWrapper::Seek(int32_t mSeconds, OHOS::NWeb::PlayerSeekMode mode)
60 {
61 return ctocpp_->Seek(mSeconds, (int32_t)mode);
62 }
63
Play()64 int32_t ArkPlayerAdapterWrapper::Play()
65 {
66 return ctocpp_->Play();
67 }
68
Pause()69 int32_t ArkPlayerAdapterWrapper::Pause()
70 {
71 return ctocpp_->Pause();
72 }
73
PrepareAsync()74 int32_t ArkPlayerAdapterWrapper::PrepareAsync()
75 {
76 return ctocpp_->PrepareAsync();
77 }
78
GetCurrentTime(int32_t & currentTime)79 int32_t ArkPlayerAdapterWrapper::GetCurrentTime(int32_t& currentTime)
80 {
81 return ctocpp_->GetCurrentTime(currentTime);
82 }
83
GetDuration(int32_t & duration)84 int32_t ArkPlayerAdapterWrapper::GetDuration(int32_t& duration)
85 {
86 return ctocpp_->GetDuration(duration);
87 }
88
SetPlaybackSpeed(OHOS::NWeb::PlaybackRateMode mode)89 int32_t ArkPlayerAdapterWrapper::SetPlaybackSpeed(OHOS::NWeb::PlaybackRateMode mode)
90 {
91 return ctocpp_->SetPlaybackSpeed((int32_t)mode);
92 }
93
94 } // namespace OHOS::ArkWeb
95