liyubing

feat: 文字直播

... ... @@ -68,19 +68,35 @@ export struct DetailPlayLiveCommon {
*/
getContentDetail() {
this.liveViewModel.getContentDetail(this.contentId, this.relId, this.relType)
.then((data: Array<ContentDetailDTO>) => {
.then(async (data: Array<ContentDetailDTO>) => {
console.log(TAG, '查询视频详情用于评论展示 getContentDetail:', JSON.stringify(data))
if (data) {
let detailData = data[0]
//人民号类型单独获取直播地址
if (detailData.rmhPlatform === 1) {
let vliveId = detailData.liveInfo.vlive[0].vliveId as string
console.error(TAG, 'vliveId==' + vliveId)
let pullStreamAddressData = await this.liveViewModel.getLiveRoomPullAddress(vliveId) as GetPullAddressBean
if (pullStreamAddressData) {
console.log(TAG, ' GetPullAddressBean:', JSON.stringify(pullStreamAddressData))
let m3u8uUrl = pullStreamAddressData.transCode[0].m3u8Url
detailData.liveInfo.vlive[0].liveUrl = m3u8uUrl
this.playUrl = m3u8uUrl
console.log(TAG, ' GetPullAddressBean:', m3u8uUrl)
}
}
this.liveLandscape =
detailData?.liveInfo?.liveLandScape //String(this.contentDetailData?.liveInfo?.liveLandScape || '')
detailData?.liveInfo?.liveLandScape
this.liveState = detailData.liveInfo?.liveState
this.contentDetailData = data[0]
console.log(TAG, '查询视频详情用于评论展示 openComment:', detailData.openComment)
this.publishCommentModel.targetId = String(detailData?.newsId || '')
this.publishCommentModel.targetRelId = String(detailData?.reLInfo?.relId || '')
this.publishCommentModel.targetTitle = detailData?.newsTitle
... ... @@ -100,18 +116,6 @@ export struct DetailPlayLiveCommon {
this.playUrl = detailData.liveInfo.vlive[0].replayUri
}
//人民号类型单独获取直播地址
if (detailData.rmhPlatform === 1) {
let vliveId = detailData.liveInfo.vlive[0].vliveId as string
console.error(TAG, 'vliveId==' + vliveId)
this.liveViewModel.getLiveRoomPullAddress(vliveId)
.then((data: GetPullAddressBean) => {
console.log(TAG, ' GetPullAddressBean:', JSON.stringify(data))
})
}
}
})
... ...
... ... @@ -27,14 +27,7 @@ export class LiveViewModel {
}
getLiveRoomPullAddress(vliveId:string){
// return new Promise<GetPullAddressBean>((success, fail) => {
// this.liveModel.getContentDetail(contentId, relId, relType).then((data) => {
// success(data)
// }).catch((message: string) => {
// fail(message)
// })
// })
async getLiveRoomPullAddress(vliveId:string) : Promise<GetPullAddressBean>{
return new Promise<GetPullAddressBean>((success, fail) => {
ContentDetailRequest.getLiveRoomPullStream(vliveId).then(async (resDTO: ResponseDTO<GetPullAddressBean>) => {
... ...
... ... @@ -15,6 +15,7 @@ export struct TopPlayComponent {
playerController?: WDAliPlayerController
// 预告片图片/视频url
@State previewUrl: string = ''
// 预告资源是否是视频资源
@State isVideoSource: boolean = false
//未开始
@State isWait: boolean = false
... ... @@ -61,6 +62,9 @@ export struct TopPlayComponent {
this.updateData()
}
/**
* 更新直播播放数据
*/
updateData() {
// 检测等待中的直播预告是否视频资源
if (this.contentDetailData.liveInfo && this.contentDetailData.liveInfo.previewType === 1
... ... @@ -91,8 +95,11 @@ export struct TopPlayComponent {
}
}
this.isEnd = this.contentDetailData?.liveInfo?.liveState === 'end' &&
StringUtils.isEmpty(this.contentDetailData?.liveInfo?.vlive[0]?.replayUri)
Logger.debug(TAG, `---0------>` + this.isWait + ' ->' + this.isLoading + ' ->' + this.isEnd)
if (!this.isWait && this.contentDetailData.liveInfo && this.contentDetailData.liveInfo.vlive.length > 0) {
let playUrl = ''
if (this.contentDetailData.liveInfo.liveState == 'running') {
... ... @@ -105,17 +112,29 @@ export struct TopPlayComponent {
this.playUrl = this.previewUrl
this.tryToPlay()
} else {
Logger.debug(TAG, `---0------>${playUrl}`)
if (StringUtils.isNotEmpty(playUrl)) {
Logger.debug(TAG, `${playUrl}`)
this.playUrl = playUrl
this.tryToPlay()
}
}
}
// 文字直播 running 状态
if (this.contentDetailData?.liveInfo?.liveWay === 1 && this.contentDetailData?.liveInfo?.liveState === 'running') {
this.isWait = true
this.isLoading = true
if (this.contentDetailData.fullColumnImgUrls && this.contentDetailData.fullColumnImgUrls.length > 0) {
this.previewUrl = this.contentDetailData.fullColumnImgUrls[0].url
} else {
this.previewUrl = ''
}
}
}
tryToPlay() {
Logger.debug(TAG, `---1------>`)
if (!this.xComponentIsLoaded) {
Logger.debug(TAG, "需要xComponent加载完成")
return
... ... @@ -136,6 +155,7 @@ export struct TopPlayComponent {
this.isLoading = false
this.isError = false
this.xComponentIsLoaded = true
Logger.debug(TAG, `---onLoad------>`)
this.tryToPlay()
}
})
... ... @@ -149,6 +169,7 @@ export struct TopPlayComponent {
// 直播房间图
Image(this.previewUrl)
.objectFit(ImageFit.Cover)
.alt($r('app.media.live_room_image_fail'))
.visibility(this.isWait || this.isEnd ? Visibility.Visible : Visibility.None)
.contrast(this.isEnd ? 0.2 : 1)
.width('100%')
... ...
... ... @@ -16,6 +16,7 @@ export struct PlayerComponent {
@State topSafeHeight: number = AppStorage.get<number>('topSafeHeight') || 0
@State imgUrl: string = ''
@State isWait: boolean = false
// 0-横屏流画面,1-竖屏幕流画面
@State liveStreamType: number | null = -1
@State playUrl: string = ''
@State isCanplay: boolean = false
... ...