diff --git a/README.en.md b/README.en.md index b3ad9facb764180553b54dc69fa456697afe7ae9..080759df83702abdb2aeaa820dac2a2c78b4ae82 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 677deccf300439d25b6916b4303df128009233a9..a71c769d8b13ae11ae13ee7c49456dddf8825c1a 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 fc3cb267b0bb30a8b6a8467690bdc42b0bc8347e..0000000000000000000000000000000000000000 --- 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 1f40f0519e2462abe49de825152baf8c0afb341f..51eecf44b9f5d1de0c4f2c9514ccd8fe512f3b7d 100644 --- a/windowpiplibrary/src/main/ets/component/VideoPlayComponent.ets +++ b/windowpiplibrary/src/main/ets/component/VideoPlayComponent.ets @@ -93,12 +93,21 @@ 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); + } + } + async startPip(): Promise { if (!this.pipController) { Logger.info(`[${TAG}] pipController create error`); return; } await this.pipController.startPiP(); + this.changePipControllerStatusStart(); } async stopPip(): Promise { @@ -130,9 +139,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 +179,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 +399,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 d40d47228a371d67ab0e418ff4cdbd525d0b62d8..4451bb38529f03e1888c7dda00ef39a16369f943 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 3d41ffb2a78c0f785d93e2f5afd468b96441830e..3b85390d45311b5f2b7c60e6764ad73c766f4dc9 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 03d2286d90f74279b277fc4c61c46eb99eb1ba59..0da169fb9c7a24ccffc489027da60f13c6d6e286 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 837b5249c1ad8a9d25d1f7395fcfcce8374d3f41..a2fd80bf445a59412642e3cff58d3bf7d50eb337 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": [