diff --git a/entry/src/main/ets/pages/NewPlayPage.ets b/entry/src/main/ets/pages/NewPlayPage.ets index 9a3b1fabb56ee2730f7ec87369e08dde7553cc67..4e7d1a021b73fa1b5e58dd0b97ef57a33fcfef4e 100644 --- a/entry/src/main/ets/pages/NewPlayPage.ets +++ b/entry/src/main/ets/pages/NewPlayPage.ets @@ -19,10 +19,6 @@ import { displaySync } from '@kit.ArkGraphics2D'; import { router } from '@kit.ArkUI'; import { CONSTANT } from '../constant/Constant'; -// XComponent width -const X_COMPONENT_WIDTH: string = '100%'; -// XComponent height -const X_COMPONENT_HEIGHT: string = '50%'; // Avatar margin const AVATAR_MARGIN = 20; // Rotate center @@ -34,25 +30,27 @@ const AVATAR_BORDER_RADIUS = 100; @Component struct NewPlayPage { @State rotateAngle: number = 0; - avPlayer: AVPlayerItem = new AVPlayerItem(); + @State avPlayer: AVPlayerItem = new AVPlayerItem(); private backDisplaySync: displaySync.DisplaySync | undefined = undefined; build() { Column() { - Image($r('app.media.back')) - .fillColor(Color.White) - .margin({ left: CONSTANT.COMMON_DISTANCE }) - .onClick(() => { - router.back(); - }) - .width(CONSTANT.STATIC_ICON_SIZE) - .height(CONSTANT.STATIC_ICON_SIZE) - .objectFit(ImageFit.Contain) + Row(){ + Image($r('app.media.back')) + .fillColor(Color.White) + .margin({ left: CONSTANT.COMMON_DISTANCE }) + .onClick(() => { + router.back(); + }) + .width(CONSTANT.STATIC_ICON_SIZE) + .height(CONSTANT.STATIC_ICON_SIZE) + .objectFit(ImageFit.Contain) + } + .justifyContent(FlexAlign.Start) + .width(CONSTANT.FULL_SIZE) SampleUnitAVPlayView({ - avPlayer: this.avPlayer, - xComponentWidth: X_COMPONENT_WIDTH, - xComponentHeight: X_COMPONENT_HEIGHT + avPlayer: $avPlayer }); Row() { @@ -74,7 +72,7 @@ struct NewPlayPage { .justifyContent(FlexAlign.End) } .height(CONSTANT.FULL_SIZE) - .alignItems(HorizontalAlign.Start) + .alignItems(HorizontalAlign.Center) .justifyContent(FlexAlign.SpaceEvenly) .backgroundColor(Color.Black) } @@ -97,6 +95,7 @@ struct NewPlayPage { } aboutToAppear(): void { + this.avPlayer.avPlayerPlay(); if (this.backDisplaySync === undefined) { this.CreateDisplaySync(); } diff --git a/entry/src/main/ets/view/SampleUnitAVPlayView.ets b/entry/src/main/ets/view/SampleUnitAVPlayView.ets index 2dd6c4b4820dbc5666391f322f210a6c2424bf6a..fddbe1ed8cbb1e27e935d080a8e97cb6f83ae003 100644 --- a/entry/src/main/ets/view/SampleUnitAVPlayView.ets +++ b/entry/src/main/ets/view/SampleUnitAVPlayView.ets @@ -15,36 +15,53 @@ import { AVPlayerItem } from '../view/AVPlayerItem'; import { CONSTANT } from '../constant/Constant'; +import { display } from '@kit.ArkUI'; // XComponent width -const X_COMPONENT_WIDTH: string = '70%'; +const X_COMPONENT_WIDTH: string = '100%'; // XComponent height const X_COMPONENT_HEIGHT: string = '50%'; // Delay time -const DELAY = 500 +const DELAY = 500; // Animation duration -const DURATION = 30000 +const DURATION = 29024; // Slider size -const SLIDER_SIZE = 4 +const SLIDER_SIZE = 4; // Surface size -const SURFACE_SIZE = 1500 +const SURFACE_SIZE = 1500; // Slider max -const SLIDER_MAX = 100 +const SLIDER_MAX = 100; // Max curtime -const CUR_MAX_TIME = 100 +const CUR_MAX_TIME = 100; @Component export default struct SampleUnitAVPlayView { - @State avPlayer: AVPlayerItem = new AVPlayerItem(); + @Link avPlayer: AVPlayerItem; @State xComponentWidth: string = X_COMPONENT_WIDTH; + @State sliderWidth: string | number = X_COMPONENT_WIDTH; @State xComponentHeight: string = X_COMPONENT_HEIGHT; @State curTime: number = 0; private xComponentController: XComponentController = new XComponentController(); setTimeInstance: number = 1 currentSurfaceID: string = '' + aboutToAppear(): void { + if (display.getFoldStatus() === display.FoldStatus.FOLD_STATUS_EXPANDED) { + this.sliderWidth = px2vp(SURFACE_SIZE); + } + + display.on('foldStatusChange', () => { + if (display.getFoldStatus() === display.FoldStatus.FOLD_STATUS_EXPANDED) { + this.sliderWidth = px2vp(SURFACE_SIZE); + } + else { + this.sliderWidth = X_COMPONENT_WIDTH; + } + }); + } + build() { - Stack({ alignContent: Alignment.BottomStart }) { + Stack({ alignContent: Alignment.Bottom }) { XComponent({ id: '', type: XComponentType.SURFACE, @@ -52,9 +69,6 @@ export default struct SampleUnitAVPlayView { }) .backgroundImage($r('app.media.video_pic')) .backgroundImageSize({ width: CONSTANT.FULL_SIZE, height: CONSTANT.FULL_SIZE }) - .onClick(() => { - this.avPlayer.avPlayer?.pause(); - }) .onLoad(() => { this.xComponentController.setXComponentSurfaceRect({ surfaceWidth: SURFACE_SIZE, surfaceHeight: SURFACE_SIZE @@ -72,11 +86,9 @@ export default struct SampleUnitAVPlayView { if (this.currentSurfaceID) { if (this.avPlayer.surfaceID !== this.currentSurfaceID) { - this.avPlayer.avPlayerPlay(); } } else { this.currentSurfaceID = this.avPlayer.surfaceID - this.avPlayer.avPlayerPlay(); } } }, DELAY) @@ -92,12 +104,12 @@ export default struct SampleUnitAVPlayView { Slider({ value: this.curTime, min: 0, max: SLIDER_MAX }) .enabled(false) .height(SLIDER_SIZE) - .width(this.xComponentWidth) + .width(this.sliderWidth) .trackThickness(3) .blockColor(Color.Red) .blockSize({ width: SLIDER_SIZE, height: SLIDER_SIZE }) .onVisibleAreaChange([0.0, 1.0], (isVisible: boolean, currentRatio: number) => { - if (isVisible && currentRatio >= 1.0) { + if (isVisible) { animateTo({ duration: DURATION, iterations: -1, diff --git a/entry/src/main/ets/view/SampleUnitVideoSecondView.ets b/entry/src/main/ets/view/SampleUnitVideoSecondView.ets index 960c7bfc0b03ff2376c31bc66bb8a668284140be..3c0d6268b27278f788a15103721a0dc43e3a706b 100644 --- a/entry/src/main/ets/view/SampleUnitVideoSecondView.ets +++ b/entry/src/main/ets/view/SampleUnitVideoSecondView.ets @@ -26,13 +26,13 @@ const X_COMPONENT_WIDTH: string = '70%'; // XComponent height const X_COMPONENT_HEIGHT: string = '50%'; // Animation duration -const DURATION = 30000 +const DURATION = 29024; // Slider size -const SLIDER_SIZE = 4 +const SLIDER_SIZE = 4; // Slider max -const SLIDER_MAX = 100 +const SLIDER_MAX = 100; // Max curtime -const CUR_MAX_TIME = 100 +const CUR_MAX_TIME = 100; @Component export default struct SampleUnitVideoSecondView { @State currentTime: number = 0; @@ -90,7 +90,7 @@ export default struct SampleUnitVideoSecondView { .blockColor(Color.Red) .blockSize({ width: SLIDER_SIZE, height: SLIDER_SIZE }) .onVisibleAreaChange([0.0, 1.0], (isVisible: boolean, currentRatio: number) => { - if (isVisible && currentRatio >= 1.0) { + if (isVisible) { animateTo({ duration: DURATION, iterations: -1, diff --git a/entry/src/main/ets/viewmodel/BasicDataSource.ets b/entry/src/main/ets/viewmodel/BasicDataSource.ets index 5135c4c2de0ba139c831f4f6614e27ff6cb1bff6..20807e9b9df615bd747a81ae5adedf2f221a55e7 100644 --- a/entry/src/main/ets/viewmodel/BasicDataSource.ets +++ b/entry/src/main/ets/viewmodel/BasicDataSource.ets @@ -87,7 +87,7 @@ class BasicDataSource implements IDataSource { let areaUnit: TitleUnitItem = new TitleUnitItem($r('app.media.avatar'), '小鱼儿', '昨天 19:12', '微博视频号', $r('app.media.honour'),); let textContext = - '亲近大海,领悟海,体会到了海的心声,海自然与你共鸣,无需可以强求,也无需费力搜寻,海,始终都会以潮声与你相亲,已其海色伴你舒适。'; + '亲近大海,领悟海,体会到了海的心声,海自然与你共鸣,无需可以强求,也无需费力搜寻,海,始终都会以潮声与你相亲,以其海色伴你舒适。'; let data: SampleUnitItem[] = [ new SampleUnitItem('video', areaUnit, textContext, buttonUnit, this.imageArray1, new VideoController(), diff --git a/screenshot/device/ltpo.png b/screenshot/device/ltpo.png index f557c9fef32f689d862029cbb1bafeb78d57f85a..e6610589fb7159d285acb540074dbbc1d25630ca 100644 Binary files a/screenshot/device/ltpo.png and b/screenshot/device/ltpo.png differ