DetailPlayLiveCommon.ets
8.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import { Action, ContentDetailDTO, GetPullAddressBean } from 'wdBean/Index';
import { LiveViewModel } from '../viewModel/LiveViewModel';
import router from '@ohos.router';
import { DetailPlayLivePage } from './DetailPlayLivePage';
import { DetailPlayVLivePage } from './DetailPlayVLivePage';
import { DateTimeUtils, Logger, ToastUtils, WindowModel } from 'wdKit/Index';
import { publishCommentModel } from 'wdComponent/src/main/ets/components/comment/model/PublishCommentModel';
import { PictureLoading } from '../widgets/vertical/PictureLoading';
import { TrackConstants, TrackingPageBrowse } from 'wdTracking/Index';
import { LiveDetailPageLogic } from '../viewModel/LiveDetailPageLogic';
import { AudioSuspensionModel } from 'wdComponent'
import { BusinessError } from '@kit.BasicServicesKit';
const TAG = 'DetailPlayLiveCommon'
/**
* 直播详情页
* @Description: 沉浸式和非沉浸式直播页面
* @Author:
* @Email:
* @CreateDate:
* @UpdateRemark: 更新说明
* @Version: 1.0
*/
@Entry
@Component
export struct DetailPlayLiveCommon {
private liveViewModel: LiveViewModel = new LiveViewModel()
pageShowTime: number = 0;
@Provide topSafeHeight: number = AppStorage.get<number>('topSafeHeight') || 0
@Provide bottomSafeHeight: number = AppStorage.get<number>('bottomSafeHeight') || 0
@Provide relId: string = ''
@Provide contentId: string = ''
@Provide relType: string = ''
// 直播状态
@Provide liveState: string = ''
// 直播样式 0-正常模式,1-隐藏直播 2-隐藏大家聊
@Provide liveStyle: number = -1
// 直播地址
@Provide playUrl: string = ''
// 全屏展示
@Provide pageShow: number = -1
// 关闭全屏
@Provide pageHide: number = -1
// 返回功能
@Provide pageBackPress: number = -1
@Provide liveDetailPageLogic :LiveDetailPageLogic = new LiveDetailPageLogic
// 直播详情内容
@Provide contentDetailData: ContentDetailDTO = {} as ContentDetailDTO
//发布评论 Model
@Provide publishCommentModel: publishCommentModel = new publishCommentModel()
// 埋点
@Provide pageId: string = TrackConstants.PageName.Live_Detail
@Provide pageName: string = TrackConstants.PageName.Live_Detail
// 是否隐藏Loading view
@State isHideLoading: boolean = false
private AudioSuspension = new AudioSuspensionModel()
@State isShowAudioCom: boolean = false
///是否已经执行过pageShow
hasPageShow: boolean = false
build() {
Column() {
// 直播预约或横屏直播统一进横屏直播
if (this.liveDetailPageLogic.isLangScapeScreenVideo()) {
// 非沉浸式直播
DetailPlayLivePage({ contentId: this.contentId, relId: this.relId, relType: this.relType })
} else if (this.liveDetailPageLogic.isVerticalScreenVideo()) {
// 沉浸式直播
DetailPlayVLivePage()
} else {
PictureLoading().visibility(this.isHideLoading ? Visibility.None : Visibility.Visible)
}
}
.height('100%')
.width('100%')
.backgroundColor(Color.Black)
// .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
}
/**
* 查询视频详情用于评论展示
*/
getContentDetail(): Promise<void> {
return new Promise<void>((resolve, reject) => {
if (this.hasPageShow) {
return
}
this.hasPageShow = true
this.liveViewModel.getContentDetail(this.contentId, this.relId, this.relType)
.then(async (data: Array<ContentDetailDTO>) => {
// console.log(TAG, '查询视频详情用于评论展示 getContentDetail:', JSON.stringify(data));
if (!data || data.length === 0) {
this.isHideLoading = true;
ToastUtils.shortToast('内容不存在');
router.back();
reject();
return;
}
const detailData = data[0];
///直播方式 0 视频直播 1 文字直播
const liveWay = detailData.liveInfo?.liveWay as number;
// 人民号类型单独获取直播地址
if (detailData.rmhPlatform === 1 && detailData.liveInfo?.liveState === 'running' && liveWay == 0) {
const vliveId = detailData.liveInfo.vlive[0].vliveId as string;
const pullStreamAddressData = await this.liveViewModel.getLiveRoomPullAddress(vliveId) as GetPullAddressBean;
if (pullStreamAddressData) {
const m3u8uUrl = pullStreamAddressData.transCode[0].m3u8Url;
detailData.liveInfo.vlive[0].liveUrl = m3u8uUrl;
this.playUrl = m3u8uUrl;
}
}
this.liveState = detailData.liveInfo?.liveState;
this.contentDetailData = detailData;
this.liveDetailPageLogic.contentDetailData = this.contentDetailData;
this.liveDetailPageLogic.liveLandscape = detailData?.liveInfo?.liveLandScape;
this.liveDetailPageLogic.liveState = detailData.liveInfo?.liveState;
this.liveDetailPageLogic.resolvingRoomImgSource();
this.liveDetailPageLogic.resolvingRoomVliveData(0);
const publishCommentModel = this.publishCommentModel;
publishCommentModel.targetId = String(detailData?.newsId || '');
publishCommentModel.targetRelId = String(detailData?.reLInfo?.relId || '');
publishCommentModel.targetTitle = detailData?.newsTitle;
publishCommentModel.targetRelType = String(detailData?.reLInfo?.relType || '');
publishCommentModel.targetRelObjectId = String(detailData?.reLInfo?.relObjectId || '');
publishCommentModel.keyArticle = String(detailData?.keyArticle || '');
publishCommentModel.targetType = String(detailData?.newsType || '');
publishCommentModel.visitorComment = String(detailData?.visitorComment || '');
publishCommentModel.commentContent = '';
this.liveStyle = detailData.liveInfo?.liveStyle;
if (detailData.liveInfo?.liveState === 'end' && liveWay == 0) {
this.playUrl = detailData.liveInfo.vlive[0].replayUri;
}
resolve();
})
.catch((error:Error) => {
Logger.debug(TAG + "error",error.message,error.name)
this.isHideLoading = true;
ToastUtils.shortToast('网络出小差了,请检查网络后重试');
router.back();
reject();
});
});
}
async onPageShow() {
this.pageShow = Math.random()
// Logger.info(TAG, 'onPageShow')
this.pageShowTime = DateTimeUtils.getTimeStamp()
WindowModel.shared.setWindowSystemBarProperties({ statusBarContentColor: '#ffffff'})
const par: Action = router.getParams() as Action;
const params = par?.params;
this.relId = params?.extra?.relId || '';
this.relType = params?.extra?.relType || '';
this.contentId = params?.contentID || '';
await this.getContentDetail()
// 判断当前窗口是否已显示,使用callback异步回调。
// Logger.info(TAG, 'this.liveState', this.liveState)
if(this.liveState !== 'wait') {
try {
let data = this.AudioSuspension.floatWindowClass.get().isWindowShowing();
// console.info(TAG, 'window is showing: ' + data);
if(data) {
this.isShowAudioCom = true
this.AudioSuspension.playerController.get()?.pause();
this.AudioSuspension.minimize()
}
} catch (exception) {
console.error(TAG, `Failed to check whether the window is showing. Cause code: ${exception.code}, message: ${exception.message}`);
}
}
}
onPageHide() {
WindowModel.shared.setWindowSystemBarProperties({ statusBarContentColor: '#000000'})
this.pageHide = Math.random()
// Logger.info(TAG, 'onPageHide')
//页面浏览
TrackingPageBrowse.trackCommonPageExposureEnd(TrackConstants.PageName.Live_Detail,
TrackConstants.PageName.Live_Detail
, Math.floor((DateTimeUtils.getTimeStamp() - this.pageShowTime) / 1000))
if(this.liveState !== 'wait') {
if (this.isShowAudioCom) {
this.AudioSuspension.showWindow()
this.isShowAudioCom = false
}
}
}
onBackPress(): boolean | void {
this.pageBackPress = Math.random()
Logger.info(TAG, 'onBackPress')
return true
}
}