From edc7c5ea5a37b16ed7e3252b59bea4fa137420e4 Mon Sep 17 00:00:00 2001 From: "DESKTOP-9FJNTIC\\gyb" <121287102@qq.com> Date: Fri, 8 Aug 2025 12:20:56 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E6=96=87=E4=BB=B6,=E4=BF=AE=E6=94=B9=E7=94=BB=E4=B8=AD?= =?UTF-8?q?=E7=94=BB=E9=9D=A2=E6=9D=BF=E9=80=BB=E8=BE=91,=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.en.md | 2 - README.md | 2 - .../main/ets/component/ImageWidthTitle.ets | 55 ------------------- .../main/ets/component/VideoPlayComponent.ets | 33 ++++++++++- windowpipsample/oh-package.json5 | 2 +- .../main/ets/entryability/EntryAbility.ets | 2 +- windowpipsample/src/main/ets/pages/Index.ets | 2 +- windowpipsample/src/main/module.json5 | 2 + 8 files changed, 36 insertions(+), 64 deletions(-) delete mode 100644 windowpiplibrary/src/main/ets/component/ImageWidthTitle.ets diff --git a/README.en.md b/README.en.md index b3ad9fa..080759d 100644 --- a/README.en.md +++ b/README.en.md @@ -22,9 +22,7 @@ Here is the English translation of your directory structure, maintaining the ori window-pip ├──windowpiplibrary/src/main/ets │ ├──component -│ │ ├──ImageWidthTitle.ets // Default player image │ │ ├──VideoPlayComponent.ets // Video playback component class -│ │ └──WindowPipComponent.ets // Picture-in-Picture component class │ ├──constants │ │ └──CommonConstants.ets // Constants class │ ├──player diff --git a/README.md b/README.md index 677decc..a71c769 100644 --- a/README.md +++ b/README.md @@ -20,9 +20,7 @@ window-pip ├──windowpiplibrary/src/main/ets │ ├──component -│ │ ├──ImageWidthTitle.ets // 播放器默认图 │ │ ├──VideoPlayComponent.ets // 视频播放组件类 -│ │ └──WindowPipComponent.ets // 画中画组件类 │ ├──constants │ │ └──CommonConstants.ets // 常量类 │ ├──player diff --git a/windowpiplibrary/src/main/ets/component/ImageWidthTitle.ets b/windowpiplibrary/src/main/ets/component/ImageWidthTitle.ets deleted file mode 100644 index fc3cb26..0000000 --- a/windowpiplibrary/src/main/ets/component/ImageWidthTitle.ets +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { CommonConstants } from '../constants/CommonConstants'; -import Logger from '../utils/Logger'; - -@Component -export struct ImageWidthTitle { - @State imageHeight: number = 0; - @Link pageInfos: NavPathStack; - @State titleResource?: Resource | undefined = undefined; - - build() { - Column() { - Image($r('app.media.btn_ground')) - .width(CommonConstants.FULL_PERCENT) - .height(this.imageHeight) - .borderRadius({ - topLeft: $r('sys.float.corner_radius_level6'), - topRight: $r('sys.float.corner_radius_level6') - }) - .objectFit(ImageFit.Cover) - .draggable(false) - Text(this.titleResource) - .fontSize($r('sys.float.Subtitle_M')) - .fontColor($r('sys.color.font_primary')) - .margin($r('sys.float.corner_radius_level4')) - } - .borderRadius($r('sys.float.corner_radius_level6')) - .backgroundColor($r('sys.color.comp_background_primary')) - .alignItems(HorizontalAlign.Start) - .onClick(() => { - this.getUIContext().getHostContext()!.eventHub.emit('onStateChange', true); - this.pageInfos?.pushPath({ name: CommonConstants.NAV_DESTINATION_NAME }, { launchMode: 3 }); - }) - .onAreaChange((oldArea: Area, newArea: Area) => { - let width: number = newArea.width as number; - this.imageHeight = width * 9 / 16; - Logger.info(`[onAreaChange] oldArea:${oldArea} ,newArea:${newArea}`); - }) - } -} - diff --git a/windowpiplibrary/src/main/ets/component/VideoPlayComponent.ets b/windowpiplibrary/src/main/ets/component/VideoPlayComponent.ets index 1f40f05..0a56bf7 100644 --- a/windowpiplibrary/src/main/ets/component/VideoPlayComponent.ets +++ b/windowpiplibrary/src/main/ets/component/VideoPlayComponent.ets @@ -93,12 +93,30 @@ export struct VideoPlayComponent { this.eventHub?.off('onStateChange'); } + changePipControllerStatusStart(): void { + if (canIUse('SystemCapability.Window.SessionManager')) { + let controlType: PiPWindow.PiPControlType = PiPWindow.PiPControlType.VIDEO_PLAY_PAUSE; + let status: PiPWindow.PiPControlStatus = PiPWindow.PiPControlStatus.PLAY; + this.pipController?.updatePiPControlStatus(controlType, status); + } + } + + changePipControllerStatusPause(): void { + if (canIUse('SystemCapability.Window.SessionManager')) { + let controlType: PiPWindow.PiPControlType = PiPWindow.PiPControlType.VIDEO_PLAY_PAUSE; + let status: PiPWindow.PiPControlStatus = PiPWindow.PiPControlStatus.PLAY; + this.pipController?.updatePiPControlStatus(controlType, status); + } + } + + async startPip(): Promise { if (!this.pipController) { Logger.info(`[${TAG}] pipController create error`); return; } await this.pipController.startPiP(); + this.changePipControllerStatusStart(); } async stopPip(): Promise { @@ -130,9 +148,19 @@ export struct VideoPlayComponent { }); this.pipController.on('stateChange', (state: PiPWindow.PiPState, reason: string) => { this.onStateChange(state, reason); + if (state === PiPWindow.PiPState.STOPPED || state === PiPWindow.PiPState.STARTED) { + this.player?.updatePlayStatus(true); + this.player?.play() + this.changePipControllerStatusStart(); + } }); this.pipController.on('controlPanelActionEvent', (event: PiPWindow.PiPActionEventType, status?: number) => { this.onActionEvent(event, status); + if (status === 0) { + this.player?.updatePlayStatus(true); + } else { + this.player?.updatePlayStatus(false); + } }); } @@ -160,8 +188,6 @@ export struct VideoPlayComponent { this.curError = $r('app.string.current_error_hint'); break; case PiPWindow.PiPState.STOPPED: - this.player?.updatePlayStatus(true); - this.player?.play(); this.curState = 'STOPPED'; this.curError = $r('app.string.current_error_hint'); break; @@ -382,12 +408,15 @@ export struct VideoPlayComponent { if (this.curState === 'STARTED') { this.stopPip(); this.hintMsgVisibility = false; + this.changePipControllerStatusStart(); } else if (this.curState === 'STOPPED') { this.startPip(); this.hintMsgVisibility = true; + this.changePipControllerStatusStart(); } else { this.createPip(); this.hintMsgVisibility = true; + this.changePipControllerStatusStart(); } }) } diff --git a/windowpipsample/oh-package.json5 b/windowpipsample/oh-package.json5 index d40d472..4451bb3 100644 --- a/windowpipsample/oh-package.json5 +++ b/windowpipsample/oh-package.json5 @@ -6,6 +6,6 @@ "author": "", "license": "", "dependencies": { - "@ohos_sample/windowpiplibrary": "file:../windowpiplibrary" + "@ohos_samples/windowpiplibrary": "file:../windowpiplibrary" } } \ No newline at end of file diff --git a/windowpipsample/src/main/ets/entryability/EntryAbility.ets b/windowpipsample/src/main/ets/entryability/EntryAbility.ets index 3d41ffb..3b85390 100644 --- a/windowpipsample/src/main/ets/entryability/EntryAbility.ets +++ b/windowpipsample/src/main/ets/entryability/EntryAbility.ets @@ -17,7 +17,7 @@ import { UIAbility } from '@kit.AbilityKit'; import { window } from '@kit.ArkUI'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; -import { WindowPipController } from '@ohos_sample/windowpiplibrary'; +import { WindowPipController } from '@ohos_samples/windowpiplibrary'; const TAG: string = '[EntryAbility]'; diff --git a/windowpipsample/src/main/ets/pages/Index.ets b/windowpipsample/src/main/ets/pages/Index.ets index 03d2286..0da169f 100644 --- a/windowpipsample/src/main/ets/pages/Index.ets +++ b/windowpipsample/src/main/ets/pages/Index.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { VideoPlayComponent } from '@ohos_sample/windowpiplibrary'; +import { VideoPlayComponent } from '@ohos_samples/windowpiplibrary'; @Entry @Component diff --git a/windowpipsample/src/main/module.json5 b/windowpipsample/src/main/module.json5 index 837b524..a2fd80b 100644 --- a/windowpipsample/src/main/module.json5 +++ b/windowpipsample/src/main/module.json5 @@ -22,6 +22,8 @@ "startWindowIcon": "$media:startIcon", "startWindowBackground": "$color:start_window_background", "exported": true, + "minWindowWidth": 1440, + "minWindowHeight": 940, "skills": [ { "entities": [ -- Gitee From 8b22bf97922ac890a7837e0011260ea6abb6f2f5 Mon Sep 17 00:00:00 2001 From: "DESKTOP-9FJNTIC\\gyb" <121287102@qq.com> Date: Fri, 8 Aug 2025 14:46:33 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/ets/component/VideoPlayComponent.ets | 9 --------- 1 file changed, 9 deletions(-) diff --git a/windowpiplibrary/src/main/ets/component/VideoPlayComponent.ets b/windowpiplibrary/src/main/ets/component/VideoPlayComponent.ets index 0a56bf7..51eecf4 100644 --- a/windowpiplibrary/src/main/ets/component/VideoPlayComponent.ets +++ b/windowpiplibrary/src/main/ets/component/VideoPlayComponent.ets @@ -101,15 +101,6 @@ export struct VideoPlayComponent { } } - changePipControllerStatusPause(): void { - if (canIUse('SystemCapability.Window.SessionManager')) { - let controlType: PiPWindow.PiPControlType = PiPWindow.PiPControlType.VIDEO_PLAY_PAUSE; - let status: PiPWindow.PiPControlStatus = PiPWindow.PiPControlStatus.PLAY; - this.pipController?.updatePiPControlStatus(controlType, status); - } - } - - async startPip(): Promise { if (!this.pipController) { Logger.info(`[${TAG}] pipController create error`); -- Gitee