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 VideoTransitionModifier extends ModifierWithKey<object> { 115 constructor(value: object) { 116 super(value); 117 } 118 static identity: Symbol = Symbol('videoTransition'); 119 applyPeer(node: KNode, reset: boolean): void { 120 if (reset) { 121 getUINativeModule().video.resetTransition(node); 122 } else { 123 getUINativeModule().video.setTransition(node, this.value); 124 } 125 } 126 checkObjectDiff(): boolean { 127 return true; 128 } 129} 130class ArkVideoComponent extends ArkComponent implements CommonMethod<VideoAttribute> { 131 constructor(nativePtr: KNode) { 132 super(nativePtr); 133 } 134 muted(value: boolean): VideoAttribute { 135 modifierWithKey(this._modifiersWithKeys, VideoMutedModifier.identity, 136 VideoMutedModifier, value); 137 return this; 138 } 139 autoPlay(value: boolean): VideoAttribute { 140 modifierWithKey(this._modifiersWithKeys, VideoAutoPlayModifier.identity, 141 VideoAutoPlayModifier, value); 142 return this; 143 } 144 controls(value: boolean): VideoAttribute { 145 modifierWithKey(this._modifiersWithKeys, VideoControlsModifier.identity, 146 VideoControlsModifier, value); 147 return this; 148 } 149 loop(value: boolean): VideoAttribute { 150 modifierWithKey(this._modifiersWithKeys, VideoLoopModifier.identity, 151 VideoLoopModifier, value); 152 return this; 153 } 154 objectFit(value: ImageFit): VideoAttribute { 155 modifierWithKey(this._modifiersWithKeys, VideoObjectFitModifier.identity, 156 VideoObjectFitModifier, value); 157 return this; 158 } 159 onStart(callback: () => void): VideoAttribute { 160 throw new Error('Method not implemented.'); 161 } 162 onPause(callback: () => void): VideoAttribute { 163 throw new Error('Method not implemented.'); 164 } 165 onFinish(event: () => void): VideoAttribute { 166 throw new Error('Method not implemented.'); 167 } 168 onFullscreenChange(callback: (event: { fullscreen: boolean }) => void): VideoAttribute { 169 throw new Error('Method not implemented.'); 170 } 171 onPrepared(callback: (event: { duration: number }) => void): VideoAttribute { 172 throw new Error('Method not implemented.'); 173 } 174 onSeeking(callback: (event: { time: number }) => void): VideoAttribute { 175 throw new Error('Method not implemented.'); 176 } 177 onSeeked(callback: (event: { time: number }) => void): VideoAttribute { 178 throw new Error('Method not implemented.'); 179 } 180 onUpdate(callback: (event: { time: number }) => void): VideoAttribute { 181 throw new Error('Method not implemented.'); 182 } 183 onError(callback: () => void): VideoAttribute { 184 throw new Error('Method not implemented.'); 185 } 186} 187// @ts-ignore 188globalThis.Video.attributeModifier = function (modifier) { 189 const elmtId = ViewStackProcessor.GetElmtIdToAccountFor(); 190 let nativeNode = getUINativeModule().getFrameNodeById(elmtId); 191 192 let component = this.createOrGetNode(elmtId, () => { 193 return new ArkVideoComponent(nativeNode); 194 }); 195 applyUIAttributes(modifier, nativeNode, component); 196 component.applyModifierPatch(); 197};