• 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  static identity: Symbol = Symbol('videoControls');
52  applyPeer(node: KNode, reset: boolean): void {
53    if (reset) {
54      getUINativeModule().video.resetControls(node);
55    } else {
56      getUINativeModule().video.setControls(node, this.value!);
57    }
58  }
59  checkObjectDiff(): boolean {
60    return !isBaseOrResourceEqual(this.stageValue, this.value);
61  }
62}
63class VideoLoopModifier extends ModifierWithKey<boolean> {
64  static identity: Symbol = Symbol('videoLoop');
65  applyPeer(node: KNode, reset: boolean): void {
66    if (reset) {
67      getUINativeModule().video.resetLoop(node);
68    } else {
69      getUINativeModule().video.setLoop(node, this.value!);
70    }
71  }
72  checkObjectDiff(): boolean {
73    return !isBaseOrResourceEqual(this.stageValue, this.value);
74  }
75}
76class VideoMutedModifier extends ModifierWithKey<boolean> {
77  static identity: Symbol = Symbol('videoMuted');
78  applyPeer(node: KNode, reset: boolean): void {
79    if (reset) {
80      getUINativeModule().video.resetMuted(node);
81    } else {
82      getUINativeModule().video.setMuted(node, this.value!);
83    }
84  }
85  checkObjectDiff(): boolean {
86    return !isBaseOrResourceEqual(this.stageValue, this.value);
87  }
88}
89class VideoOpacityModifier extends ModifierWithKey<number | Resource> {
90  constructor(value: number | Resource) {
91    super(value);
92  }
93  static identity: Symbol = Symbol('videoOpacity');
94  applyPeer(node: KNode, reset: boolean): void {
95    if (reset) {
96      getUINativeModule().video.resetOpacity(node);
97    } else {
98      getUINativeModule().video.setOpacity(node, this.value!);
99    }
100  }
101  checkObjectDiff(): boolean {
102    return !isBaseOrResourceEqual(this.stageValue, this.value);
103  }
104}
105class VideoTransitionModifier extends ModifierWithKey<object> {
106  constructor(value: object) {
107    super(value);
108  }
109  static identity: Symbol = Symbol('videoTransition');
110  applyPeer(node: KNode, reset: boolean): void {
111    if (reset) {
112      getUINativeModule().video.resetTransition(node);
113    } else {
114      getUINativeModule().video.setTransition(node, this.value);
115    }
116  }
117  checkObjectDiff(): boolean {
118    return true;
119  }
120}
121class ArkVideoComponent extends ArkComponent implements CommonMethod<VideoAttribute> {
122  constructor(nativePtr: KNode, classType?: ModifierType) {
123    super(nativePtr, classType);
124  }
125  muted(value: boolean): VideoAttribute {
126    modifierWithKey(this._modifiersWithKeys, VideoMutedModifier.identity,
127      VideoMutedModifier, value);
128    return this;
129  }
130  autoPlay(value: boolean): VideoAttribute {
131    modifierWithKey(this._modifiersWithKeys, VideoAutoPlayModifier.identity,
132      VideoAutoPlayModifier, value);
133    return this;
134  }
135  controls(value: boolean): VideoAttribute {
136    modifierWithKey(this._modifiersWithKeys, VideoControlsModifier.identity,
137      VideoControlsModifier, value);
138    return this;
139  }
140  loop(value: boolean): VideoAttribute {
141    modifierWithKey(this._modifiersWithKeys, VideoLoopModifier.identity,
142      VideoLoopModifier, value);
143    return this;
144  }
145  objectFit(value: ImageFit): VideoAttribute {
146    modifierWithKey(this._modifiersWithKeys, VideoObjectFitModifier.identity,
147      VideoObjectFitModifier, value);
148    return this;
149  }
150  onStart(callback: () => void): VideoAttribute {
151    throw new Error('Method not implemented.');
152  }
153  onPause(callback: () => void): VideoAttribute {
154    throw new Error('Method not implemented.');
155  }
156  onFinish(event: () => void): VideoAttribute {
157    throw new Error('Method not implemented.');
158  }
159  onFullscreenChange(callback: (event: { fullscreen: boolean }) => void): VideoAttribute {
160    throw new Error('Method not implemented.');
161  }
162  onPrepared(callback: (event: { duration: number }) => void): VideoAttribute {
163    throw new Error('Method not implemented.');
164  }
165  onSeeking(callback: (event: { time: number }) => void): VideoAttribute {
166    throw new Error('Method not implemented.');
167  }
168  onSeeked(callback: (event: { time: number }) => void): VideoAttribute {
169    throw new Error('Method not implemented.');
170  }
171  onUpdate(callback: (event: { time: number }) => void): VideoAttribute {
172    throw new Error('Method not implemented.');
173  }
174  onError(callback: () => void): VideoAttribute {
175    throw new Error('Method not implemented.');
176  }
177  onStop(callback: () => void): VideoAttribute {
178    throw new Error('Method not implemented.');
179  }
180}
181// @ts-ignore
182globalThis.Video.attributeModifier = function (modifier: ArkComponent): void {
183  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
184    return new ArkVideoComponent(nativePtr);
185  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
186    return new modifierJS.VideoModifier(nativePtr, classType);
187  });
188};
189