liyubing

feat:

1、直播详情页面 横屏  进入后台 暂停播放,回到页面恢复播放
... ... @@ -7,10 +7,9 @@ import mediaquery from '@ohos.mediaquery';
import { Logger, WindowModel } from 'wdKit/Index';
import { router, window } from '@kit.ArkUI';
import { WDAliPlayerController } from 'wdPlayer/Index';
import { LiveEmptyComponent, LiveOperRowListView } from 'wdComponent';
import { LiveOperRowListView } from 'wdComponent';
import { publishCommentModel } from 'wdComponent/src/main/ets/components/comment/model/PublishCommentModel';
import { TrackConstants, TrackingContent, TrackParamConvert } from 'wdTracking/Index';
import { LiveDetailPageLogic } from '../viewModel/LiveDetailPageLogic';
let TAG: string = 'DetailPlayLivePage';
... ... @@ -57,7 +56,6 @@ export struct DetailPlayLivePage {
this.getLiveDetails()
this.getLiveRoomData()
console.error(TAG, 'this.publishCommentModel', this.publishCommentModel.targetId)
}
async aboutToDisappear() {
... ...
... ... @@ -306,12 +306,13 @@ export struct PlayUIComponent {
.width(24)
.height(24)
.onClick(() => {
WindowModel.shared.setSpecificSystemBarEnabled(false)
this.displayDirection =
this.displayDirection == DisplayDirection.VERTICAL ? DisplayDirection.VIDEO_HORIZONTAL :
DisplayDirection.VERTICAL
WindowModel.shared.setSpecificSystemBarEnabled(false)
WindowModel.shared.setPreferredOrientation(this.displayDirection == DisplayDirection.VERTICAL ?
window.Orientation.PORTRAIT :
window.Orientation.LANDSCAPE_INVERTED)
... ...
... ... @@ -35,6 +35,17 @@ export struct TopPlayComponent {
private playUrl: string = ""
private xComponentIsLoaded: boolean = false
@Consume liveDetailPageLogic: LiveDetailPageLogic
@Consume @Watch('pageShowChange') pageShow: number
@Consume @Watch('pageHideChange') pageHide: number
init: boolean = false
pageShowChange() {
this.playerController?.play()
}
pageHideChange() {
this.playerController?.pause()
}
aboutToAppear(): void {
if (this.playerController) {
... ... @@ -71,7 +82,7 @@ export struct TopPlayComponent {
updateData() {
// 检测垫片
if (this.liveDetailPageLogic.showPad){
if (this.liveDetailPageLogic.showPad) {
this.isHideLoading = true
this.isWait = true
this.previewUrl = this.liveDetailPageLogic.imgUrl
... ...
... ... @@ -43,22 +43,26 @@ export struct WDPlayerRenderLiveView {
private playerController?: WDAliPlayerController;
private xComponentController: XComponentController = new XComponentController();
onLoad?: ((event?: object) => void);
videoWidth: number = 0
videoHeight: number = 0
@State videoWidth: number = 0
@State videoHeight: number = 0
@State videoRatio: number = 16 / 9
@State selfSize: Size = new Size('100%', '100%');
private insId: string = "WDPlayerRenderLiveView" + insIndex;
aboutToAppear() {
MGPlayRenderViewIns.add();
insIndex++;
if (!this.playerController) {
return
}
//this.init = true
this.playerController.onVideoSizeChange = (width: number, height: number) => {
// console.log(`WDPlayerRenderView onVideoSizeChange width:${width} videoTop:${height}`)
this.videoWidth = width;
this.videoHeight = height;
this.videoRatio = width / height
this.updateLayout()
}
}
... ... @@ -80,9 +84,9 @@ export struct WDPlayerRenderLiveView {
.onLoad(async (event) => {
Logger.info(TAG, 'onLoad')
let surfaceId = this.xComponentController.getXComponentSurfaceId()
this.xComponentController.setXComponentSurfaceSize({
surfaceWidth: 1920,
surfaceHeight: 720
this.xComponentController.setXComponentSurfaceRect({
surfaceWidth: this.videoWidth,
surfaceHeight: this.videoHeight
});
if (enableAliPlayer) {
this.playerController?.setSurfaceId(this.insId)
... ... @@ -93,8 +97,8 @@ export struct WDPlayerRenderLiveView {
this.onLoad(event)
}
})
.width(this.selfSize.width)
.height(this.selfSize.height)
// .width(this.selfSize.width)
// .height(this.selfSize.height)
}
.id(this.insId)
.onAreaChange(() => {
... ... @@ -107,15 +111,40 @@ export struct WDPlayerRenderLiveView {
}
updateLayout() {
let info = componentUtils.getRectangleById(this.insId);
if (info.size.width > 0 && info.size.height > 0 && this.videoHeight > 0 && this.videoWidth > 0) {
if (info.size.width / info.size.height > this.videoWidth / this.videoHeight) {
let scale = info.size.height / this.videoHeight;
this.selfSize = new Size((this.videoWidth * scale / info.size.width) * 100 + "%", '100%');
} else {
let scale = info.size.width / this.videoWidth;
this.selfSize = new Size('100%', (this.videoHeight * scale / info.size.height) * 100 + "%");
Logger.debug(TAG, "播放器区域变化: " + JSON.stringify(info))
Logger.debug(TAG, "xComponent rect: " + JSON.stringify(this.xComponentController.getXComponentSurfaceRect()))
if (info.size.width > 0 && info.size.height > 0) {
// 竖屏
if (this.videoHeight > 0 && this.videoWidth > 0 && this.videoWidth < this.videoHeight) {
let ratio = this.videoWidth / this.videoHeight
const height = info.size.width / ratio
// 竖屏,缩放高度大于 视频区域高度
if (height > info.size.height) {
Logger.debug(TAG, "ratio = " + ratio + " ==> new height = " + height)
Logger.debug(TAG, "高度固定,求宽度: " + info.size.height * ratio)
this.xComponentController.setXComponentSurfaceRect({
surfaceWidth: info.size.height * ratio,
surfaceHeight: info.size.height
});
return
}
}
this.xComponentController.setXComponentSurfaceRect({
surfaceWidth: info.size.width,
surfaceHeight: info.size.height
});
}
}
}
\ No newline at end of file
... ...