fanmingyou3_wd

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

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