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