wangyujian_wd

feat:1)直播详情【横竖屏】切换逻辑添加

@@ -19,4 +19,6 @@ export { DurationEnum } from './src/main/ets/enum/DurationEnum'; @@ -19,4 +19,6 @@ export { DurationEnum } from './src/main/ets/enum/DurationEnum';
19 19
20 export { ScreenType } from './src/main/ets/enum/ScreenType'; 20 export { ScreenType } from './src/main/ets/enum/ScreenType';
21 21
22 -export { SpConstants } from './src/main/ets/constants/SpConstants';  
  22 +export { SpConstants } from './src/main/ets/constants/SpConstants';
  23 +
  24 +export { DisplayDirection } from './src/main/ets/constants/VideoConstants';
  1 +export enum DisplayDirection {
  2 + VERTICAL,
  3 + VIDEO_HORIZONTAL
  4 +}
@@ -4,10 +4,17 @@ import { BottomComponent } from '../widgets/details/BottomComponent'; @@ -4,10 +4,17 @@ import { BottomComponent } from '../widgets/details/BottomComponent';
4 import { TabComponent } from '../widgets/details/TabComponent'; 4 import { TabComponent } from '../widgets/details/TabComponent';
5 import { TopPlayComponent } from '../widgets/details/video/TopPlayComponet'; 5 import { TopPlayComponent } from '../widgets/details/video/TopPlayComponet';
6 import router from '@ohos.router'; 6 import router from '@ohos.router';
  7 +import { DisplayDirection } from 'wdConstant/Index';
  8 +import mediaquery from '@ohos.mediaquery';
  9 +import { Logger, WindowModel } from 'wdKit/Index';
  10 +import { window } from '@kit.ArkUI';
  11 +import { devicePLSensorManager } from 'wdDetailPlayApi/Index';
7 12
8 @Entry 13 @Entry
9 @Component 14 @Component
10 export struct DetailPlayLivePage { 15 export struct DetailPlayLivePage {
  16 + //横竖屏,默认竖屏
  17 + @Provide displayDirection: DisplayDirection = DisplayDirection.VERTICAL
11 TAG: string = 'DetailPlayLivePage'; 18 TAG: string = 'DetailPlayLivePage';
12 liveViewModel: LiveViewModel = new LiveViewModel() 19 liveViewModel: LiveViewModel = new LiveViewModel()
13 @State relId: string = '' 20 @State relId: string = ''
@@ -18,7 +25,17 @@ export struct DetailPlayLivePage { @@ -18,7 +25,17 @@ export struct DetailPlayLivePage {
18 @State tabs: string[] = ['直播间', '大家聊'] 25 @State tabs: string[] = ['直播间', '大家聊']
19 26
20 aboutToAppear(): void { 27 aboutToAppear(): void {
21 - //https://pdapis.pdnews.cn/api/rmrb-bff-display-zh/content/zh/c/content/detail?relId=500005302448&relType=1&contentId=20000016340 28 + //监听屏幕横竖屏变化
  29 + let listener = mediaquery.matchMediaSync('(orientation: landscape)');
  30 + listener.on("change", (mediaQueryResult) => {
  31 + Logger.info(this.TAG,`change;${mediaQueryResult.matches}`)
  32 + if (mediaQueryResult.matches) {
  33 + this.displayDirection = DisplayDirection.VIDEO_HORIZONTAL
  34 + } else {
  35 + this.displayDirection = DisplayDirection.VERTICAL
  36 + }
  37 + // WindowModel.shared.setMainWindowFullScreen(this.displayDirection == DisplayDirection.VIDEO_HORIZONTAL)
  38 + })
22 let par: Action = router.getParams() as Action; 39 let par: Action = router.getParams() as Action;
23 let params = par?.params; 40 let params = par?.params;
24 this.relId = params?.extra?.relId || ''; 41 this.relId = params?.extra?.relId || '';
@@ -31,15 +48,24 @@ export struct DetailPlayLivePage { @@ -31,15 +48,24 @@ export struct DetailPlayLivePage {
31 build() { 48 build() {
32 Column() { 49 Column() {
33 TopPlayComponent() 50 TopPlayComponent()
  51 + .layoutWeight(211)
34 TabComponent({ tabs: this.tabs }) 52 TabComponent({ tabs: this.tabs })
  53 + .layoutWeight(503)
  54 + .visibility(this.displayDirection == DisplayDirection.VERTICAL ? Visibility.Visible : Visibility.None)
35 BottomComponent() 55 BottomComponent()
  56 + .visibility(this.displayDirection == DisplayDirection.VERTICAL ? Visibility.Visible : Visibility.None)
36 } 57 }
37 .height('100%') 58 .height('100%')
38 .width('100%') 59 .width('100%')
39 } 60 }
40 61
41 onPageShow(): void { 62 onPageShow(): void {
  63 + WindowModel.shared.setPreferredOrientation(window.Orientation.AUTO_ROTATION_RESTRICTED);
  64 + }
42 65
  66 + onPageHide(): void {
  67 + devicePLSensorManager.devicePLSensorOff();
  68 + WindowModel.shared.setPreferredOrientation(window.Orientation.AUTO_ROTATION_RESTRICTED);
43 } 69 }
44 70
45 getLiveDetails() { 71 getLiveDetails() {
@@ -72,4 +98,19 @@ export struct DetailPlayLivePage { @@ -72,4 +98,19 @@ export struct DetailPlayLivePage {
72 aboutToDisappear(): void { 98 aboutToDisappear(): void {
73 99
74 } 100 }
  101 +
  102 + onBackPress(): boolean | void {
  103 + if (this.displayDirection == DisplayDirection.VERTICAL) {
  104 + router.back()
  105 + } else {
  106 + this.displayDirection = DisplayDirection.VERTICAL
  107 + }
  108 + WindowModel.shared.setPreferredOrientation(this.displayDirection == DisplayDirection.VERTICAL ?
  109 + window.Orientation.PORTRAIT :
  110 + window.Orientation.LANDSCAPE)
  111 + devicePLSensorManager.devicePLSensorOn(this.displayDirection == DisplayDirection.VERTICAL ?
  112 + window.Orientation.PORTRAIT :
  113 + window.Orientation.LANDSCAPE);
  114 + return true
  115 + }
75 } 116 }
1 import { window } from '@kit.ArkUI' 1 import { window } from '@kit.ArkUI'
2 import { NumberFormatterUtils, WindowModel } from 'wdKit/Index' 2 import { NumberFormatterUtils, WindowModel } from 'wdKit/Index'
3 -  
4 import { devicePLSensorManager } from 'wdDetailPlayApi/Index' 3 import { devicePLSensorManager } from 'wdDetailPlayApi/Index'
5 import { DateFormatUtil, WDPlayerController } from 'wdPlayer/Index' 4 import { DateFormatUtil, WDPlayerController } from 'wdPlayer/Index'
6 import { LiveDetailsBean, LiveRoomDataBean } from 'wdBean/Index' 5 import { LiveDetailsBean, LiveRoomDataBean } from 'wdBean/Index'
  6 +import { DisplayDirection } from 'wdConstant/Index'
7 7
8 -@Entry  
9 @Component 8 @Component
10 export struct PlayUIComponent { 9 export struct PlayUIComponent {
11 playerController: WDPlayerController = new WDPlayerController(); 10 playerController: WDPlayerController = new WDPlayerController();
12 //菜单键是否可见 11 //菜单键是否可见
13 @State isMenuVisible: boolean = true 12 @State isMenuVisible: boolean = true
14 - @State isFullScreen: boolean = false  
15 @Consume liveDetailsBean: LiveDetailsBean 13 @Consume liveDetailsBean: LiveDetailsBean
16 @Consume liveRoomDataBean: LiveRoomDataBean 14 @Consume liveRoomDataBean: LiveRoomDataBean
17 @State currentTime: string = '' 15 @State currentTime: string = ''
@@ -19,6 +17,7 @@ export struct PlayUIComponent { @@ -19,6 +17,7 @@ export struct PlayUIComponent {
19 @State progressVal: number = 0; 17 @State progressVal: number = 0;
20 //是否处于播放状态中 18 //是否处于播放状态中
21 @State isPlayStatus: boolean = true 19 @State isPlayStatus: boolean = true
  20 + @Consume displayDirection: DisplayDirection
22 21
23 aboutToAppear(): void { 22 aboutToAppear(): void {
24 //播放进度监听 23 //播放进度监听
@@ -47,10 +46,19 @@ export struct PlayUIComponent { @@ -47,10 +46,19 @@ export struct PlayUIComponent {
47 Image($r('app.media.icon_arrow_left_white')) 46 Image($r('app.media.icon_arrow_left_white'))
48 .width(24) 47 .width(24)
49 .aspectRatio(1) 48 .aspectRatio(1)
50 - .visibility(Visibility.None) 49 + .visibility(this.displayDirection == DisplayDirection.VIDEO_HORIZONTAL ? Visibility.Visible : Visibility.None)
51 .margin({ 50 .margin({
52 right: 10 51 right: 10
53 }) 52 })
  53 + .onClick(() => {
  54 + this.displayDirection = DisplayDirection.VERTICAL
  55 + WindowModel.shared.setPreferredOrientation(this.displayDirection == DisplayDirection.VERTICAL ?
  56 + window.Orientation.PORTRAIT :
  57 + window.Orientation.LANDSCAPE)
  58 + devicePLSensorManager.devicePLSensorOn(this.displayDirection == DisplayDirection.VERTICAL ?
  59 + window.Orientation.PORTRAIT :
  60 + window.Orientation.LANDSCAPE);
  61 + })
54 if (this.liveDetailsBean.liveInfo?.liveState != 'wait') { 62 if (this.liveDetailsBean.liveInfo?.liveState != 'wait') {
55 Text(this.liveDetailsBean.newsTitle) 63 Text(this.liveDetailsBean.newsTitle)
56 .maxLines(1) 64 .maxLines(1)
@@ -66,7 +74,7 @@ export struct PlayUIComponent { @@ -66,7 +74,7 @@ export struct PlayUIComponent {
66 Image($r('app.media.icon_share')) 74 Image($r('app.media.icon_share'))
67 .width(24) 75 .width(24)
68 .aspectRatio(1) 76 .aspectRatio(1)
69 - .visibility(Visibility.None) 77 + .visibility(this.displayDirection == DisplayDirection.VIDEO_HORIZONTAL ? Visibility.Visible : Visibility.None)
70 } 78 }
71 .width('100%') 79 .width('100%')
72 .alignItems(VerticalAlign.Center) 80 .alignItems(VerticalAlign.Center)
@@ -196,9 +204,13 @@ export struct PlayUIComponent { @@ -196,9 +204,13 @@ export struct PlayUIComponent {
196 .width(24) 204 .width(24)
197 .height(24) 205 .height(24)
198 .onClick(() => { 206 .onClick(() => {
199 - this.isFullScreen = !this.isFullScreen  
200 - WindowModel.shared.setPreferredOrientation(this.isFullScreen ? window.Orientation.LANDSCAPE : window.Orientation.PORTRAIT);  
201 - devicePLSensorManager.devicePLSensorOn(this.isFullScreen ? window.Orientation.LANDSCAPE : window.Orientation.PORTRAIT); 207 + this.displayDirection = this.displayDirection == DisplayDirection.VERTICAL ? DisplayDirection.VIDEO_HORIZONTAL : DisplayDirection.VERTICAL
  208 + WindowModel.shared.setPreferredOrientation(this.displayDirection == DisplayDirection.VERTICAL ?
  209 + window.Orientation.PORTRAIT :
  210 + window.Orientation.LANDSCAPE)
  211 + devicePLSensorManager.devicePLSensorOn(this.displayDirection == DisplayDirection.VERTICAL ?
  212 + window.Orientation.PORTRAIT :
  213 + window.Orientation.LANDSCAPE);
202 }) 214 })
203 } 215 }
204 .alignItems(VerticalAlign.Center) 216 .alignItems(VerticalAlign.Center)
@@ -47,7 +47,6 @@ export struct TopPlayComponent { @@ -47,7 +47,6 @@ export struct TopPlayComponent {
47 .visibility(this.isWait ? Visibility.Visible : Visibility.None) 47 .visibility(this.isWait ? Visibility.Visible : Visibility.None)
48 PlayUIComponent({ playerController: this.playerController }) 48 PlayUIComponent({ playerController: this.playerController })
49 } 49 }
50 - .height(211)  
51 .width('100%') 50 .width('100%')
52 } 51 }
53 52
@@ -45,7 +45,7 @@ export struct WDPlayerRenderLiveView { @@ -45,7 +45,7 @@ export struct WDPlayerRenderLiveView {
45 videoWidth: number = 0 45 videoWidth: number = 0
46 videoHeight: number = 0 46 videoHeight: number = 0
47 @State selfSize: Size = new Size('100%', '100%'); 47 @State selfSize: Size = new Size('100%', '100%');
48 - private insId: string = "WDPlayRenderView" + insIndex; 48 + private insId: string = "WDPlayerRenderLiveView" + insIndex;
49 49
50 aboutToAppear() { 50 aboutToAppear() {
51 MGPlayRenderViewIns.add(); 51 MGPlayRenderViewIns.add();
@@ -97,7 +97,7 @@ export struct WDPlayerRenderLiveView { @@ -97,7 +97,7 @@ export struct WDPlayerRenderLiveView {
97 } 97 }
98 .id(this.insId) 98 .id(this.insId)
99 .onAreaChange(() => { 99 .onAreaChange(() => {
100 - // this.updateLayout() 100 + this.updateLayout()
101 }) 101 })
102 .backgroundColor("#000000") 102 .backgroundColor("#000000")
103 .justifyContent(FlexAlign.Center) 103 .justifyContent(FlexAlign.Center)