From 927158bfbd1707b74fe0f7baec7485eef03ffe72 Mon Sep 17 00:00:00 2001 From: taosheng11 <8371186+taosheng11@user.noreply.gitee.com> Date: Fri, 25 Jul 2025 02:55:45 +0000 Subject: [PATCH] update PowerAnalysis/BackgroundPowerSample/entry/src/main/ets/pages/buffer_power_example.ets. Signed-off-by: taosheng11 <8371186+taosheng11@user.noreply.gitee.com> --- .../main/ets/pages/buffer_power_example.ets | 79 +++++++++++++++---- 1 file changed, 65 insertions(+), 14 deletions(-) diff --git a/PowerAnalysis/BackgroundPowerSample/entry/src/main/ets/pages/buffer_power_example.ets b/PowerAnalysis/BackgroundPowerSample/entry/src/main/ets/pages/buffer_power_example.ets index 549b936f..82058a5b 100644 --- a/PowerAnalysis/BackgroundPowerSample/entry/src/main/ets/pages/buffer_power_example.ets +++ b/PowerAnalysis/BackgroundPowerSample/entry/src/main/ets/pages/buffer_power_example.ets @@ -3,6 +3,31 @@ */ import webview from '@ohos.web.webview'; +import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize($r('app.float.page_text_font_size')) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + this.message = 'Welcome'; + }) + } + .height('100%') + .width('100%') + } +} // [Start buffer_power_case_1] @Component @@ -30,20 +55,46 @@ struct MyWebComponent { // [End buffer_power_case_1] // [Start buffer_power_case_2] -Video() -// ... -.onVisibleAreaChange({ratios: [0.0, 1.0], expectedUpdateInterval: 1000}, (isExpanding: boolean, currentRatio: number) => { - if (isExpanding && currentRatio >= 1.0) { - console.info('Component is completely visiable.'); - if (this.controller) { - this.controller.start(); - } - } - if (!isExpanding && currentRatio <= 0.0) { - console.info('Component is completely invisible.'); - if (this.controller) { - this.controller.pause(); +@Component +struct MyVideoComponent { + @State videoSrc: Resource | string = $rawfile('video1.mp4'); + private controller: VideoController = new VideoController(); + + + build() { + Column() { + Video({ + src: this.videoSrc, + controller: this.controller + }) + .width('100%') + .height(600) + .onPrepared(() => { + this.controller.start(); + }) + .onDrop((e: DragEvent) => { + let record = e.getData().getRecords()[0]; + if (record.getType() == uniformTypeDescriptor.UniformDataType.VIDEO) { + let videoInfo = record as unifiedDataChannel.Video; + this.videoSrc = videoInfo.videoUri; + } + }) + // 确保视频组件完全可见时播放,完全不可见时停止 + .onVisibleAreaChange([0.0], (isExpanding: boolean, currentRatio: number) => { + if (isExpanding && currentRatio >= 1.0) { + console.info('Component is completely visiable.'); + if (this.controller) { + this.controller.start(); + } + } + if (!isExpanding && currentRatio <= 0.0) { + console.info('Component is completely invisible.'); + if (this.controller) { + this.controller.pause(); + } + } + }) } } -}) +} // [End buffer_power_case_2] \ No newline at end of file -- Gitee