fanmingyou3_wd

// 根据视频朝向展示详情,

// 横屏视频:1(进入竖屏,立即展示半屏播放窗口,当切换横屏时,再展示全部播放窗口;后续可再转换到竖屏):
  // 竖屏视频:2(进入竖屏,直接展示全屏播放窗口,且不能切换横屏);
1 import { Logger, ResourcesUtils } from 'wdKit'; 1 import { Logger, ResourcesUtils } from 'wdKit';
2 -import { HttpUrlUtils, ResponseDTO, WDHttp } from 'wdNetwork'  
3 -import { ContentDetailDTO } from 'wdBean' 2 +import { HttpUrlUtils, ResponseDTO, WDHttp } from 'wdNetwork';
  3 +import { ContentDetailDTO } from 'wdBean';
4 import HashMap from '@ohos.util.HashMap'; 4 import HashMap from '@ohos.util.HashMap';
5 5
6 const TAG = 'ContentDetailRequest'; 6 const TAG = 'ContentDetailRequest';
1 import sensor from '@ohos.sensor'; 1 import sensor from '@ohos.sensor';
2 import window from '@ohos.window'; 2 import window from '@ohos.window';
3 -import { WindowModel } from 'wdKit' 3 +import { WindowModel } from 'wdKit';
4 4
5 -export class devicePLSensorManager{  
6 - public static devicePLSensorOn(targetOrientation:number) { 5 +export class devicePLSensorManager {
  6 + public static devicePLSensorOn(targetOrientation: number) {
7 try { 7 try {
8 sensor.off(sensor.SensorId.ACCELEROMETER); 8 sensor.off(sensor.SensorId.ACCELEROMETER);
9 - } catch (e) {} 9 + } catch (e) {
  10 + }
10 let requestOrientation = -1; // sensor旋转的角度 11 let requestOrientation = -1; // sensor旋转的角度
11 let num = -1; 12 let num = -1;
12 - try{ 13 + try {
13 // 订阅加速度传感器数据 14 // 订阅加速度传感器数据
14 sensor.on(sensor.SensorId.ACCELEROMETER, (response: sensor.AccelerometerResponse) => { 15 sensor.on(sensor.SensorId.ACCELEROMETER, (response: sensor.AccelerometerResponse) => {
15 - if(num < 5){  
16 - num ++; 16 + if (num < 5) {
  17 + num++;
17 return; 18 return;
18 } else { 19 } else {
19 num = -1; 20 num = -1;
@@ -35,20 +36,20 @@ export class devicePLSensorManager{ @@ -35,20 +36,20 @@ export class devicePLSensorManager{
35 } 36 }
36 } 37 }
37 if (orientation == -1) return; // 水平方向不处理 38 if (orientation == -1) return; // 水平方向不处理
38 - if (orientation > 315 || orientation < 45){ 39 + if (orientation > 315 || orientation < 45) {
39 requestOrientation = window.Orientation.PORTRAIT; 40 requestOrientation = window.Orientation.PORTRAIT;
40 } 41 }
41 - else if (orientation > 45 && orientation < 135){ 42 + else if (orientation > 45 && orientation < 135) {
42 requestOrientation = window.Orientation.LANDSCAPE; 43 requestOrientation = window.Orientation.LANDSCAPE;
43 } 44 }
44 - else if (orientation > 225 && orientation < 315){ 45 + else if (orientation > 225 && orientation < 315) {
45 requestOrientation = window.Orientation.LANDSCAPE_INVERTED; 46 requestOrientation = window.Orientation.LANDSCAPE_INVERTED;
46 } 47 }
47 - if(targetOrientation == window.Orientation.PORTRAIT && requestOrientation == window.Orientation.PORTRAIT){ 48 + if (targetOrientation == window.Orientation.PORTRAIT && requestOrientation == window.Orientation.PORTRAIT) {
48 WindowModel.shared.setPreferredOrientation(window.Orientation.AUTO_ROTATION_RESTRICTED); 49 WindowModel.shared.setPreferredOrientation(window.Orientation.AUTO_ROTATION_RESTRICTED);
49 sensor.off(sensor.SensorId.ACCELEROMETER); 50 sensor.off(sensor.SensorId.ACCELEROMETER);
50 } 51 }
51 - if(targetOrientation == window.Orientation.LANDSCAPE && (requestOrientation == window.Orientation.LANDSCAPE || requestOrientation == window.Orientation.LANDSCAPE_INVERTED)){ 52 + if (targetOrientation == window.Orientation.LANDSCAPE && (requestOrientation == window.Orientation.LANDSCAPE || requestOrientation == window.Orientation.LANDSCAPE_INVERTED)) {
52 WindowModel.shared.setPreferredOrientation(window.Orientation.AUTO_ROTATION_RESTRICTED); 53 WindowModel.shared.setPreferredOrientation(window.Orientation.AUTO_ROTATION_RESTRICTED);
53 sensor.off(sensor.SensorId.ACCELEROMETER); 54 sensor.off(sensor.SensorId.ACCELEROMETER);
54 } 55 }
@@ -63,9 +64,10 @@ export class devicePLSensorManager{ @@ -63,9 +64,10 @@ export class devicePLSensorManager{
63 } 64 }
64 } 65 }
65 66
66 - public static devicePLSensorOff(){ 67 + public static devicePLSensorOff() {
67 try { 68 try {
68 sensor.off(sensor.SensorId.ACCELEROMETER); 69 sensor.off(sensor.SensorId.ACCELEROMETER);
69 - } catch (e) {} 70 + } catch (e) {
  71 + }
70 } 72 }
71 } 73 }
1 -import { SpeedBean, PlayerConstants } from 'wdPlayer'; 1 +import { PlayerConstants, SpeedBean } from 'wdPlayer';
2 2
3 // 倍速Dialog 3 // 倍速Dialog
4 @Preview 4 @Preview
@@ -2,8 +2,8 @@ import router from '@ohos.router'; @@ -2,8 +2,8 @@ import router from '@ohos.router';
2 import mediaquery from '@ohos.mediaquery'; 2 import mediaquery from '@ohos.mediaquery';
3 import window from '@ohos.window'; 3 import window from '@ohos.window';
4 import { Action } from 'wdBean'; 4 import { Action } from 'wdBean';
5 -import { WindowModel, SPHelper, Logger } from 'wdKit';  
6 -import { WDPlayerController, WDPlayerRenderView, PlayerConstants } from 'wdPlayer'; 5 +import { Logger, SPHelper, WindowModel } from 'wdKit';
  6 +import { PlayerConstants, WDPlayerController, WDPlayerRenderView } from 'wdPlayer';
7 import { devicePLSensorManager } from 'wdDetailPlayApi'; 7 import { devicePLSensorManager } from 'wdDetailPlayApi';
8 import { PlayControlViewContainer } from '../view/PlayControlViewContainer'; 8 import { PlayControlViewContainer } from '../view/PlayControlViewContainer';
9 import { PlayerDetailContainer } from '../view/PlayerDetailContainer'; 9 import { PlayerDetailContainer } from '../view/PlayerDetailContainer';
@@ -35,16 +35,18 @@ export struct DetailPlayShortVideoPage { @@ -35,16 +35,18 @@ export struct DetailPlayShortVideoPage {
35 @Provide message?: string = undefined 35 @Provide message?: string = undefined
36 @Provide newsSummary?: string = undefined 36 @Provide newsSummary?: string = undefined
37 @Provide progressVal: number = 0; 37 @Provide progressVal: number = 0;
  38 + @Provide videoLandScape?: number = 1; // 视频朝向, 横屏视频:1;竖屏视频:2
38 39
39 playVMChanged(name: string) { 40 playVMChanged(name: string) {
40 this.url = this.playVM.url 41 this.url = this.playVM.url
41 this.newsSourceName = this.playVM.newsSourceName 42 this.newsSourceName = this.playVM.newsSourceName
42 this.title = this.playVM.title 43 this.title = this.playVM.title
  44 + this.newsSummary = this.playVM.newsSummary
  45 + this.videoLandScape = this.playVM.videoLandScape ?? 1
43 this.curContId = this.playVM.contentId 46 this.curContId = this.playVM.contentId
44 this.nextContId = this.playVM.nextContId 47 this.nextContId = this.playVM.nextContId
45 this.canStart = this.playVM.canStart; 48 this.canStart = this.playVM.canStart;
46 this.message = this.playVM.message 49 this.message = this.playVM.message
47 - this.newsSummary = this.playVM.newsSummary  
48 } 50 }
49 51
50 aboutToAppear() { 52 aboutToAppear() {
1 import { WDPlayerController } from 'wdPlayer'; 1 import { WDPlayerController } from 'wdPlayer';
2 -import { PlayerTitleComment } from './PlayerTitleComment' 2 +import { PlayerTitleComment } from './PlayerTitleComment';
3 3
4 /** 4 /**
5 * 非全屏状态-(播放页面底部)非播放区域 5 * 非全屏状态-(播放页面底部)非播放区域
1 -import router from '@ohos.router';  
2 1
3 const FULL_PARENT: string = '100%'; 2 const FULL_PARENT: string = '100%';
4 3
1 -import router from '@ohos.router';  
2 import { ToastUtils } from 'wdKit'; 1 import { ToastUtils } from 'wdKit';
3 2
4 export interface OperationItem { 3 export interface OperationItem {
1 import window from '@ohos.window'; 1 import window from '@ohos.window';
2 -import { WindowModel, SPHelper } from 'wdKit';  
3 -import { DateFormatUtil, WDPlayerController, PlayerConstants } from 'wdPlayer'; 2 +import { SPHelper, WindowModel } from 'wdKit';
  3 +import { DateFormatUtil, PlayerConstants, WDPlayerController } from 'wdPlayer';
4 import { devicePLSensorManager, PlayError } from 'wdDetailPlayApi'; 4 import { devicePLSensorManager, PlayError } from 'wdDetailPlayApi';
5 import { PlayerProgressBar } from './PlayerProgressBar'; 5 import { PlayerProgressBar } from './PlayerProgressBar';
6 import { PlayerTitle } from './PlayerTitle'; 6 import { PlayerTitle } from './PlayerTitle';
@@ -8,6 +8,56 @@ export struct PlayerDetailContainer { @@ -8,6 +8,56 @@ export struct PlayerDetailContainer {
8 @BuilderParam playControlView: () => void 8 @BuilderParam playControlView: () => void
9 @BuilderParam detailView: () => void 9 @BuilderParam detailView: () => void
10 @Consume isFullScreen: boolean 10 @Consume isFullScreen: boolean
  11 + @Consume videoLandScape?: number // 视频朝向, 横屏视频:1;竖屏视频:2
  12 +
  13 + aboutToAppear() {
  14 + console.log(`PlayerDetailContainer aboutToAppear`)
  15 + }
  16 +
  17 + buildVideoHeight() {
  18 + let videoHeight: string | number = 200
  19 + if (this.videoLandScape == 2) {
  20 + videoHeight = '100%'
  21 + } else {
  22 + videoHeight = 200
  23 + }
  24 + console.log(`PlayerDetailContainer buildVideoHeight:${videoHeight} `)
  25 + return videoHeight
  26 + }
  27 +
  28 + buildVideoTo() {
  29 + let videoTop: number;
  30 + if (this.videoLandScape == 2) {
  31 + videoTop = 0
  32 + } else {
  33 + videoTop = 174
  34 + }
  35 + console.log(`PlayerDetailContainer videoTop:${videoTop} `)
  36 + return videoTop
  37 + }
  38 +
  39 + buildVideoBottom() {
  40 + let videoBottom: number;
  41 + if (this.videoLandScape == 2) {
  42 + videoBottom = 0
  43 + } else {
  44 + videoBottom = 320
  45 + }
  46 + console.log(`PlayerDetailContainer buildVideoBottom:${videoBottom} `)
  47 + return videoBottom
  48 + }
  49 +
  50 + isShowBottomView() {
  51 + console.log(`PlayerDetailContainer videoLandScape:${this.videoLandScape} `)
  52 + let isShowBottom: boolean = false
  53 + if (this.isFullScreen) {
  54 + isShowBottom = false
  55 + } else {
  56 + isShowBottom = true
  57 + }
  58 + console.log(`PlayerDetailContainer isShowBottom:${isShowBottom} `)
  59 + return isShowBottom
  60 + }
11 61
12 build() { 62 build() {
13 RelativeContainer() { 63 RelativeContainer() {
@@ -28,19 +78,21 @@ export struct PlayerDetailContainer { @@ -28,19 +78,21 @@ export struct PlayerDetailContainer {
28 } 78 }
29 .width('100%') 79 .width('100%')
30 // .aspectRatio(this.isFullScreen ? 0.1 : 16 / 9.0) // 若width值确定,当aspectRatio值越小,则height值越大 80 // .aspectRatio(this.isFullScreen ? 0.1 : 16 / 9.0) // 若width值确定,当aspectRatio值越小,则height值越大
31 - .height(this.isFullScreen ? '100%' : 200)  
32 - .margin({ top: this.isFullScreen ? 0 : 174 }) 81 + .height(this.isFullScreen ? '100%' : this.buildVideoHeight())
  82 + .margin({ top: this.isFullScreen ? 0 : this.buildVideoTo() })
  83 + // .margin({ bottom: this.isFullScreen ? 0 : this.buildVideoBottom() })
33 .alignRules({ 84 .alignRules({
34 top: { anchor: '__container__', align: VerticalAlign.Top }, 85 top: { anchor: '__container__', align: VerticalAlign.Top },
35 // middle: { anchor: '__container__', align: HorizontalAlign.Center } 86 // middle: { anchor: '__container__', align: HorizontalAlign.Center }
36 }) 87 })
37 .id('stk_player_container') 88 .id('stk_player_container')
38 89
39 - if (!this.isFullScreen) { 90 + if (this.isShowBottomView()) {
40 Row() { 91 Row() {
41 this.detailView() 92 this.detailView()
42 } 93 }
43 .width('100%') 94 .width('100%')
  95 + // .opacity(0.3)
44 .alignRules({ 96 .alignRules({
45 bottom: { anchor: '__container__', align: VerticalAlign.Bottom }, 97 bottom: { anchor: '__container__', align: VerticalAlign.Bottom },
46 // middle: { anchor: '__container__', align: HorizontalAlign.Center } 98 // middle: { anchor: '__container__', align: HorizontalAlign.Center }
1 import window from '@ohos.window'; 1 import window from '@ohos.window';
2 import { WindowModel } from 'wdKit'; 2 import { WindowModel } from 'wdKit';
3 -import { WDPlayerController, PlayerConstants } from 'wdPlayer';  
4 -import { devicePLSensorManager } from 'wdDetailPlayApi';  
5 -import { PlaySpeedDialog } from 'wdDetailPlayApi'; 3 +import { PlayerConstants, WDPlayerController } from 'wdPlayer';
  4 +import { devicePLSensorManager, PlaySpeedDialog } from 'wdDetailPlayApi';
6 import { PlayViewModel } from '../viewmodel/PlayViewModel'; 5 import { PlayViewModel } from '../viewmodel/PlayViewModel';
7 6
8 /** 7 /**
1 import router from '@ohos.router'; 1 import router from '@ohos.router';
2 import window from '@ohos.window'; 2 import window from '@ohos.window';
3 -import deviceInfo from '@ohos.deviceInfo' 3 +import deviceInfo from '@ohos.deviceInfo';
4 import { WindowModel } from 'wdKit'; 4 import { WindowModel } from 'wdKit';
5 import { WDPlayerController } from 'wdPlayer'; 5 import { WDPlayerController } from 'wdPlayer';
6 import { devicePLSensorManager } from 'wdDetailPlayApi'; 6 import { devicePLSensorManager } from 'wdDetailPlayApi';
1 import router from '@ohos.router'; 1 import router from '@ohos.router';
2 import window from '@ohos.window'; 2 import window from '@ohos.window';
3 -import deviceInfo from '@ohos.deviceInfo' 3 +import deviceInfo from '@ohos.deviceInfo';
4 import { WindowModel } from 'wdKit'; 4 import { WindowModel } from 'wdKit';
5 import { WDPlayerController } from 'wdPlayer'; 5 import { WDPlayerController } from 'wdPlayer';
6 import { devicePLSensorManager } from 'wdDetailPlayApi'; 6 import { devicePLSensorManager } from 'wdDetailPlayApi';
@@ -16,6 +16,7 @@ export struct PlayerTitleComment { @@ -16,6 +16,7 @@ export struct PlayerTitleComment {
16 @Consume isFullScreen: boolean; 16 @Consume isFullScreen: boolean;
17 @State comment: string = ''; 17 @State comment: string = '';
18 @Consume progressVal: number; 18 @Consume progressVal: number;
  19 + @Consume videoLandScape?: number
19 20
20 aboutToAppear() { 21 aboutToAppear() {
21 } 22 }
@@ -43,6 +44,7 @@ export struct PlayerTitleComment { @@ -43,6 +44,7 @@ export struct PlayerTitleComment {
43 .backgroundColor(Color.Gray) 44 .backgroundColor(Color.Gray)
44 .borderRadius(10) 45 .borderRadius(10)
45 .alignItems(VerticalAlign.Center) 46 .alignItems(VerticalAlign.Center)
  47 + .visibility(this.videoLandScape == 2 ? Visibility.Hidden : Visibility.Visible)
46 .onClick(() => { 48 .onClick(() => {
47 this.isFullScreen = !this.isFullScreen; 49 this.isFullScreen = !this.isFullScreen;
48 WindowModel.shared.setPreferredOrientation(window.Orientation.LANDSCAPE); 50 WindowModel.shared.setPreferredOrientation(window.Orientation.LANDSCAPE);
@@ -104,7 +106,6 @@ export struct PlayerTitleComment { @@ -104,7 +106,6 @@ export struct PlayerTitleComment {
104 .width(44) 106 .width(44)
105 .aspectRatio(1) 107 .aspectRatio(1)
106 .padding(13) 108 .padding(13)
107 - .margin({ left: 13 })  
108 .onClick(() => { 109 .onClick(() => {
109 if (this.isFullScreen) { 110 if (this.isFullScreen) {
110 if (deviceInfo.deviceType != "phone") { 111 if (deviceInfo.deviceType != "phone") {
@@ -11,13 +11,17 @@ export class PlayViewModel { @@ -11,13 +11,17 @@ export class PlayViewModel {
11 contentId: string 11 contentId: string
12 relId: string 12 relId: string
13 relType: string 13 relType: string
14 - newsSourceName?:string 14 + newsSourceName?: string
15 title?: string 15 title?: string
  16 + newsSummary?: string
16 url?: string 17 url?: string
  18 + // 视频朝向,
  19 + // 横屏视频:1(进入竖屏,立即展示半屏播放窗口,当切换横屏时,再展示全部播放窗口;后续可再转换到竖屏):
  20 + // 竖屏视频:2(进入竖屏,直接展示全屏播放窗口,且不能切换横屏);
  21 + videoLandScape?: number
17 nextContId?: string 22 nextContId?: string
18 canStart?: boolean 23 canStart?: boolean
19 message?: string 24 message?: string
20 - newsSummary?: string  
21 25
22 constructor() { 26 constructor() {
23 // todo: 27 // todo:
@@ -55,12 +59,16 @@ export class PlayViewModel { @@ -55,12 +59,16 @@ export class PlayViewModel {
55 Logger.error(TAG, `getContentDetailData then body is empty`); 59 Logger.error(TAG, `getContentDetailData then body is empty`);
56 return 60 return
57 } 61 }
58 - this.newsSourceName = resDTO.data[0].newsSourceName  
59 - this.title = resDTO.data[0].newsTitle  
60 - this.url = resDTO.data[0].videoInfo[0].videoUrl 62 + let contentDetailDTO: ContentDetailDTO = resDTO.data[0]
  63 + this.newsSourceName = contentDetailDTO.newsSourceName
  64 + this.title = contentDetailDTO.newsTitle
  65 + this.newsSummary = contentDetailDTO.newsSummary
  66 + if (contentDetailDTO.videoInfo?.length > 0) {
  67 + this.url = contentDetailDTO.videoInfo[0].videoUrl
  68 + this.videoLandScape = contentDetailDTO.videoInfo[0].videoLandScape
  69 + }
61 this.canStart = true; 70 this.canStart = true;
62 this.message = ''; 71 this.message = '';
63 - this.newsSummary = resDTO.data[0].newsSummary  
64 }).catch((err: BusinessError) => { 72 }).catch((err: BusinessError) => {
65 Logger.error(TAG, `getContentDetailData catch, error.code : ${err.code}, error.message:${err.message}`); 73 Logger.error(TAG, `getContentDetailData catch, error.code : ${err.code}, error.message:${err.message}`);
66 // todo: 74 // todo:
@@ -56,6 +56,7 @@ export struct WDPlayerRenderView { @@ -56,6 +56,7 @@ export struct WDPlayerRenderView {
56 } 56 }
57 57
58 this.playerController.onVideoSizeChange = (width: number, height: number) => { 58 this.playerController.onVideoSizeChange = (width: number, height: number) => {
  59 + // console.log(`WDPlayerRenderView onVideoSizeChange width:${width} videoTop:${height}`)
59 this.videoWidth = width; 60 this.videoWidth = width;
60 this.videoHeight = height; 61 this.videoHeight = height;
61 this.updateLayout() 62 this.updateLayout()