PlayerDetailContainer.ets 2.77 KB
/**
 * 详情view&播放器view的容器布局组件
 */
@Entry
@Component
export struct PlayerDetailContainer {
  @BuilderParam playerView: () => void
  @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() {
      Stack() {
        Row() {
          this.playerView()
        }
        .height('100%')
        .width('100%')
        .zIndex(0)

        Row() {
          this.playControlView()
        }
        .height('100%')
        .width('100%')
        .zIndex(1)
      }
      .width('100%')
      // .aspectRatio(this.isFullScreen ? 0.1 : 16 / 9.0) // 若width值确定,当aspectRatio值越小,则height值越大
      .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.isShowBottomView()) {
        Row() {
          this.detailView()
        }
        .width('100%')
        // .opacity(0.3)
        .alignRules({
          bottom: { anchor: '__container__', align: VerticalAlign.Bottom },
          // middle: { anchor: '__container__', align: HorizontalAlign.Center }
        })
        .id('row_bottomView')
      }
    }
    .width('100%')
    .height('100%')
  }
}