• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/// <reference path='./import.ts' />
17
18class VideoObjectFitModifier extends ModifierWithKey<ImageFit> {
19  constructor(value: ImageFit) {
20    super(value);
21  }
22  static identity: Symbol = Symbol('videoObjectFit');
23  applyPeer(node: KNode, reset: boolean): void {
24    if (reset) {
25      getUINativeModule().video.resetObjectFit(node);
26    } else {
27      getUINativeModule().video.setObjectFit(node, this.value!);
28    }
29  }
30  checkObjectDiff(): boolean {
31    return !isBaseOrResourceEqual(this.stageValue, this.value);
32  }
33}
34class VideoAutoPlayModifier extends ModifierWithKey<boolean> {
35  constructor(value: boolean) {
36    super(value);
37  }
38  static identity: Symbol = Symbol('videoAutoPlayr');
39  applyPeer(node: KNode, reset: boolean): void {
40    if (reset) {
41      getUINativeModule().video.resetAutoPlay(node);
42    } else {
43      getUINativeModule().video.setAutoPlay(node, this.value!);
44    }
45  }
46  checkObjectDiff(): boolean {
47    return !isBaseOrResourceEqual(this.stageValue, this.value);
48  }
49}
50class VideoControlsModifier extends ModifierWithKey<boolean> {
51  constructor(value: boolean) {
52    super(value);
53  }
54  static identity: Symbol = Symbol('videoControls');
55  applyPeer(node: KNode, reset: boolean): void {
56    if (reset) {
57      getUINativeModule().video.resetControls(node);
58    } else {
59      getUINativeModule().video.setControls(node, this.value!);
60    }
61  }
62  checkObjectDiff(): boolean {
63    return !isBaseOrResourceEqual(this.stageValue, this.value);
64  }
65}
66class VideoLoopModifier extends ModifierWithKey<boolean> {
67  constructor(value: boolean) {
68    super(value);
69  }
70  static identity: Symbol = Symbol('videoLoop');
71  applyPeer(node: KNode, reset: boolean): void {
72    if (reset) {
73      getUINativeModule().video.resetLoop(node);
74    } else {
75      getUINativeModule().video.setLoop(node, this.value!);
76    }
77  }
78  checkObjectDiff(): boolean {
79    return !isBaseOrResourceEqual(this.stageValue, this.value);
80  }
81}
82class VideoMutedModifier extends ModifierWithKey<boolean> {
83  constructor(value: boolean) {
84    super(value);
85  }
86  static identity: Symbol = Symbol('videoMuted');
87  applyPeer(node: KNode, reset: boolean): void {
88    if (reset) {
89      getUINativeModule().video.resetMuted(node);
90    } else {
91      getUINativeModule().video.setMuted(node, this.value!);
92    }
93  }
94  checkObjectDiff(): boolean {
95    return !isBaseOrResourceEqual(this.stageValue, this.value);
96  }
97}
98class VideoOpacityModifier extends ModifierWithKey<number | Resource> {
99  constructor(value: number | Resource) {
100    super(value);
101  }
102  static identity: Symbol = Symbol('videoOpacity');
103  applyPeer(node: KNode, reset: boolean): void {
104    if (reset) {
105      getUINativeModule().video.resetOpacity(node);
106    } else {
107      getUINativeModule().video.setOpacity(node, this.value!);
108    }
109  }
110  checkObjectDiff(): boolean {
111    return !isBaseOrResourceEqual(this.stageValue, this.value);
112  }
113}
114class VideoSurfaceBackgroundColorModifier extends ModifierWithKey<ResourceColor> {
115  constructor(value: ResourceColor) {
116    super(value);
117  }
118  static identity: Symbol = Symbol('videoSurfaceBackgroundColor');
119  applyPeer(node: KNode, reset: boolean): void {
120    if (reset) {
121      getUINativeModule().video.resetVideoSurfaceBackgroundColor(node);
122    } else {
123      getUINativeModule().video.setVideoSurfaceBackgroundColor(node, this.value);
124    }
125  }
126
127  checkObjectDiff(): boolean {
128    return !isBaseOrResourceEqual(this.stageValue, this.value);
129  }
130}
131class VideoTransitionModifier extends ModifierWithKey<object> {
132  constructor(value: object) {
133    super(value);
134  }
135  static identity: Symbol = Symbol('videoTransition');
136  applyPeer(node: KNode, reset: boolean): void {
137    if (reset) {
138      getUINativeModule().video.resetTransition(node);
139    } else {
140      getUINativeModule().video.setTransition(node, this.value);
141    }
142  }
143  checkObjectDiff(): boolean {
144    return true;
145  }
146}
147class VideoEnableShortcutKeyModifier extends ModifierWithKey<boolean> {
148  constructor(value: boolean) {
149    super(value);
150  }
151  static identity: Symbol = Symbol('videoEnableShortcutKey');
152  applyPeer(node: KNode, reset: boolean): void {
153    if (reset) {
154      getUINativeModule().video.resetShortcutKeyEnabled(node);
155    } else {
156      getUINativeModule().video.setShortcutKeyEnabled(node, this.value!);
157    }
158  }
159  checkObjectDiff(): boolean {
160    return !isBaseOrResourceEqual(this.stageValue, this.value);
161  }
162}
163class ArkVideoComponent extends ArkComponent implements CommonMethod<VideoAttribute> {
164  constructor(nativePtr: KNode, classType?: ModifierType) {
165    super(nativePtr, classType);
166  }
167  muted(value: boolean): VideoAttribute {
168    modifierWithKey(this._modifiersWithKeys, VideoMutedModifier.identity,
169      VideoMutedModifier, value);
170    return this;
171  }
172  autoPlay(value: boolean): VideoAttribute {
173    modifierWithKey(this._modifiersWithKeys, VideoAutoPlayModifier.identity,
174      VideoAutoPlayModifier, value);
175    return this;
176  }
177  surfaceBackgroundColor(value: ResourceColor): VideoAttribute {
178    modifierWithKey(this._modifiersWithKeys, VideoSurfaceBackgroundColorModifier.identity,
179      VideoSurfaceBackgroundColorModifier, value);
180    return this;
181  }
182  controls(value: boolean): VideoAttribute {
183    modifierWithKey(this._modifiersWithKeys, VideoControlsModifier.identity,
184      VideoControlsModifier, value);
185    return this;
186  }
187  loop(value: boolean): VideoAttribute {
188    modifierWithKey(this._modifiersWithKeys, VideoLoopModifier.identity,
189      VideoLoopModifier, value);
190    return this;
191  }
192  objectFit(value: ImageFit): VideoAttribute {
193    modifierWithKey(this._modifiersWithKeys, VideoObjectFitModifier.identity,
194      VideoObjectFitModifier, value);
195    return this;
196  }
197  enableShortcutKey(value: boolean): VideoAttribute {
198    modifierWithKey(this._modifiersWithKeys, VideoEnableShortcutKeyModifier.identity,
199      VideoEnableShortcutKeyModifier, value);
200    return this;
201  }
202  onStart(callback: () => void): VideoAttribute {
203    throw new Error('Method not implemented.');
204  }
205  onPause(callback: () => void): VideoAttribute {
206    throw new Error('Method not implemented.');
207  }
208  onFinish(event: () => void): VideoAttribute {
209    throw new Error('Method not implemented.');
210  }
211  onFullscreenChange(callback: (event: { fullscreen: boolean }) => void): VideoAttribute {
212    throw new Error('Method not implemented.');
213  }
214  onPrepared(callback: (event: { duration: number }) => void): VideoAttribute {
215    throw new Error('Method not implemented.');
216  }
217  onSeeking(callback: (event: { time: number }) => void): VideoAttribute {
218    throw new Error('Method not implemented.');
219  }
220  onSeeked(callback: (event: { time: number }) => void): VideoAttribute {
221    throw new Error('Method not implemented.');
222  }
223  onUpdate(callback: (event: { time: number }) => void): VideoAttribute {
224    throw new Error('Method not implemented.');
225  }
226  onError(callback: () => void): VideoAttribute {
227    throw new Error('Method not implemented.');
228  }
229  onStop(callback: () => void): VideoAttribute {
230    throw new Error('Method not implemented.');
231  }
232}
233// @ts-ignore
234globalThis.Video.attributeModifier = function (modifier: ArkComponent): void {
235  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
236    return new ArkVideoComponent(nativePtr);
237  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
238    return new modifierJS.VideoModifier(nativePtr, classType);
239  });
240};
241