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 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_video_bridge.h"
16
17 #include "bridge/declarative_frontend/engine/jsi/jsi_types.h"
18 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.h"
19 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
20 #include "core/components/common/layout/constants.h"
21 #include "core/interfaces/native/node/api.h"
22
23 namespace OHOS::Ace::NG {
24 constexpr int32_t NUM_0 = 0;
25 constexpr int32_t NUM_1 = 1;
26
SetAutoPlay(ArkUIRuntimeCallInfo * runtimeCallInfo)27 ArkUINativeModuleValue VideoBridge::SetAutoPlay(ArkUIRuntimeCallInfo* runtimeCallInfo)
28 {
29 EcmaVM* vm = runtimeCallInfo->GetVM();
30 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
31 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
32 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
33 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
34 if (secondArg->IsBoolean()) {
35 uint32_t autoPlay = static_cast<uint32_t>(secondArg->ToBoolean(vm)->Value());
36 GetArkUIInternalNodeAPI()->GetVideoModifier().SetAutoPlay(nativeNode, autoPlay);
37 } else {
38 GetArkUIInternalNodeAPI()->GetVideoModifier().ResetAutoPlay(nativeNode);
39 }
40 return panda::JSValueRef::Undefined(vm);
41 }
42
ResetAutoPlay(ArkUIRuntimeCallInfo * runtimeCallInfo)43 ArkUINativeModuleValue VideoBridge::ResetAutoPlay(ArkUIRuntimeCallInfo* runtimeCallInfo)
44 {
45 EcmaVM* vm = runtimeCallInfo->GetVM();
46 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
47 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
48 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
49 GetArkUIInternalNodeAPI()->GetVideoModifier().ResetAutoPlay(nativeNode);
50 return panda::JSValueRef::Undefined(vm);
51 }
52
SetControls(ArkUIRuntimeCallInfo * runtimeCallInfo)53 ArkUINativeModuleValue VideoBridge::SetControls(ArkUIRuntimeCallInfo* runtimeCallInfo)
54 {
55 EcmaVM* vm = runtimeCallInfo->GetVM();
56 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
57 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
58 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
59 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
60 if (secondArg->IsBoolean()) {
61 uint32_t controlsValue = static_cast<uint32_t>(secondArg->ToBoolean(vm)->Value());
62 GetArkUIInternalNodeAPI()->GetVideoModifier().SetVideoControls(nativeNode, controlsValue);
63 } else {
64 GetArkUIInternalNodeAPI()->GetVideoModifier().ResetVideoControls(nativeNode);
65 }
66 return panda::JSValueRef::Undefined(vm);
67 }
68
ResetControls(ArkUIRuntimeCallInfo * runtimeCallInfo)69 ArkUINativeModuleValue VideoBridge::ResetControls(ArkUIRuntimeCallInfo* runtimeCallInfo)
70 {
71 EcmaVM* vm = runtimeCallInfo->GetVM();
72 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
73 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
74 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
75 GetArkUIInternalNodeAPI()->GetVideoModifier().ResetVideoControls(nativeNode);
76 return panda::JSValueRef::Undefined(vm);
77 }
78
SetObjectFit(ArkUIRuntimeCallInfo * runtimeCallInfo)79 ArkUINativeModuleValue VideoBridge::SetObjectFit(ArkUIRuntimeCallInfo* runtimeCallInfo)
80 {
81 EcmaVM* vm = runtimeCallInfo->GetVM();
82 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
83 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
84 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
85 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
86 if (secondArg->IsInt()) {
87 int32_t imageFit = secondArg->Int32Value(vm);
88 GetArkUIInternalNodeAPI()->GetVideoModifier().SetVideoObjectFit(nativeNode, imageFit);
89 } else {
90 GetArkUIInternalNodeAPI()->GetVideoModifier().ResetVideoObjectFit(nativeNode);
91 }
92 return panda::JSValueRef::Undefined(vm);
93 }
94
ResetObjectFit(ArkUIRuntimeCallInfo * runtimeCallInfo)95 ArkUINativeModuleValue VideoBridge::ResetObjectFit(ArkUIRuntimeCallInfo* runtimeCallInfo)
96 {
97 EcmaVM* vm = runtimeCallInfo->GetVM();
98 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
99 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
100 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
101 GetArkUIInternalNodeAPI()->GetVideoModifier().ResetVideoObjectFit(nativeNode);
102 return panda::JSValueRef::Undefined(vm);
103 }
104
SetLoop(ArkUIRuntimeCallInfo * runtimeCallInfo)105 ArkUINativeModuleValue VideoBridge::SetLoop(ArkUIRuntimeCallInfo* runtimeCallInfo)
106 {
107 EcmaVM* vm = runtimeCallInfo->GetVM();
108 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
109 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
110 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
111 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
112 if (secondArg->IsBoolean()) {
113 uint32_t value = static_cast<uint32_t>(secondArg->ToBoolean(vm)->Value());
114 GetArkUIInternalNodeAPI()->GetVideoModifier().SetVideoLoop(nativeNode, value);
115 } else {
116 GetArkUIInternalNodeAPI()->GetVideoModifier().ResetVideoLoop(nativeNode);
117 }
118 return panda::JSValueRef::Undefined(vm);
119 }
120
ResetLoop(ArkUIRuntimeCallInfo * runtimeCallInfo)121 ArkUINativeModuleValue VideoBridge::ResetLoop(ArkUIRuntimeCallInfo* runtimeCallInfo)
122 {
123 EcmaVM* vm = runtimeCallInfo->GetVM();
124 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
125 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
126 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
127 GetArkUIInternalNodeAPI()->GetVideoModifier().ResetVideoLoop(nativeNode);
128 return panda::JSValueRef::Undefined(vm);
129 }
130
SetMuted(ArkUIRuntimeCallInfo * runtimeCallInfo)131 ArkUINativeModuleValue VideoBridge::SetMuted(ArkUIRuntimeCallInfo* runtimeCallInfo)
132 {
133 EcmaVM* vm = runtimeCallInfo->GetVM();
134 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
135 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
136 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
137 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
138 if (secondArg->IsBoolean()) {
139 uint32_t value = static_cast<uint32_t>(secondArg->ToBoolean(vm)->Value());
140 GetArkUIInternalNodeAPI()->GetVideoModifier().SetVideoMuted(nativeNode, value);
141 } else {
142 GetArkUIInternalNodeAPI()->GetVideoModifier().ResetVideoMuted(nativeNode);
143 }
144 return panda::JSValueRef::Undefined(vm);
145 }
146
ResetMuted(ArkUIRuntimeCallInfo * runtimeCallInfo)147 ArkUINativeModuleValue VideoBridge::ResetMuted(ArkUIRuntimeCallInfo* runtimeCallInfo)
148 {
149 EcmaVM* vm = runtimeCallInfo->GetVM();
150 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
151 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
152 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
153 GetArkUIInternalNodeAPI()->GetVideoModifier().ResetVideoMuted(nativeNode);
154 return panda::JSValueRef::Undefined(vm);
155 }
156
SetOpacity(ArkUIRuntimeCallInfo * runtimeCallInfo)157 ArkUINativeModuleValue VideoBridge::SetOpacity(ArkUIRuntimeCallInfo* runtimeCallInfo)
158 {
159 EcmaVM* vm = runtimeCallInfo->GetVM();
160 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
161 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
162 Local<JSValueRef> opacityArg = runtimeCallInfo->GetCallArgRef(1);
163 void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
164 double opacity;
165 if (!ArkTSUtils::ParseJsDouble(vm, opacityArg, opacity)) {
166 GetArkUIInternalNodeAPI()->GetVideoModifier().ResetVideoOpacity(nativeNode);
167 } else {
168 GetArkUIInternalNodeAPI()->GetVideoModifier().SetVideoOpacity(nativeNode, opacity);
169 }
170 return panda::JSValueRef::Undefined(vm);
171 }
172
ResetOpacity(ArkUIRuntimeCallInfo * runtimeCallInfo)173 ArkUINativeModuleValue VideoBridge::ResetOpacity(ArkUIRuntimeCallInfo* runtimeCallInfo)
174 {
175 EcmaVM *vm = runtimeCallInfo->GetVM();
176 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
177 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
178 void *nativeNode = nodeArg->ToNativePointer(vm)->Value();
179 GetArkUIInternalNodeAPI()->GetVideoModifier().ResetVideoOpacity(nativeNode);
180 return panda::JSValueRef::Undefined(vm);
181 }
182
SetTransition(ArkUIRuntimeCallInfo * runtimeCallInfo)183 ArkUINativeModuleValue VideoBridge::SetTransition(ArkUIRuntimeCallInfo* runtimeCallInfo)
184 {
185 EcmaVM* vm = runtimeCallInfo->GetVM();
186 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
187 CommonBridge::SetTransitionPassThrough(runtimeCallInfo);
188 return panda::JSValueRef::Undefined(vm);
189 }
190
ResetTransition(ArkUIRuntimeCallInfo * runtimeCallInfo)191 ArkUINativeModuleValue VideoBridge::ResetTransition(ArkUIRuntimeCallInfo* runtimeCallInfo)
192 {
193 EcmaVM* vm = runtimeCallInfo->GetVM();
194 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
195 CommonBridge::ResetTransitionPassThrough(runtimeCallInfo);
196 return panda::JSValueRef::Undefined(vm);
197 }
198 } // namespace OHOS::Ace::NG