PlayViewModel.ets
3.25 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
import { BusinessError } from '@ohos.base'
import { Logger, ToastUtils } from 'wdKit'
import { ResponseDTO } from 'wdNetwork'
import { ContentDetailRequest } from 'wdDetailPlayApi'
import { ContentDetailDTO, RmhInfoDTO, UserInfoDTO } from 'wdBean'
const TAG = 'PlayViewModel';
@Observed
export class PlayViewModel {
contentId: string
relId: string
relType: string
newsSourceName?: string
newsTitle?: string
editorName?: string
newsSummary?: string
rmhInfo?: RmhInfoDTO | null
userInfo?: UserInfoDTO | null
url?: string
// 视频朝向,
// 横屏视频:1(进入竖屏,立即展示半屏播放窗口,当切换横屏时,再展示全部播放窗口;后续可再转换到竖屏):
// 竖屏视频:2(进入竖屏,直接展示全屏播放窗口,且不能切换横屏);
videoLandScape?: number
nextContId?: string
canStart?: boolean
message?: string
constructor() {
// todo:
this.contentId = '30013266075'
this.relId = '500000301942'
this.relType = '1'
// this.getGlobalInfo();
}
playWithContentId(contentId: string) {
this.contentId = contentId;
this.getContentDetailData() // 包括播放地址PlayUrl
}
playWithIds(contentId: string, relId: string, relType: string) {
this.contentId = contentId;
this.relId = relId;
this.relType = relType;
this.getContentDetailData() // 包括播放地址PlayUrl
}
getContentDetailData() {
ContentDetailRequest.getContentDetail({
contentId: this.contentId,
relId: this.relId,
relType: this.relType
}).then((resDTO: ResponseDTO<ContentDetailDTO[]>) => {
if (!resDTO) {
Logger.error(TAG, 'getContentDetailData then resDTO is empty');
return
}
// Logger.info(TAG, "getNavData then,navResDTO.timeStamp:" + navResDTO.timeStamp);
if (!resDTO.data || resDTO.data.length == 0) {
Logger.error(TAG, `getContentDetailData then body is empty`);
return
}
let contentDetailDTO: ContentDetailDTO = resDTO.data[0]
Logger.info(TAG, JSON.stringify(contentDetailDTO))
this.newsTitle = contentDetailDTO.newsTitle
this.editorName = contentDetailDTO.editorName
this.newsSummary = contentDetailDTO.newsSummary
this.userInfo = contentDetailDTO.userInfo
this.rmhInfo = contentDetailDTO.rmhInfo
if (contentDetailDTO.videoInfo?.length > 0) {
this.url = contentDetailDTO.videoInfo[0].videoUrl
this.videoLandScape = contentDetailDTO.videoInfo[0].videoLandScape
}
if (contentDetailDTO.authorList?.length > 0) {
this.newsSourceName = contentDetailDTO.authorList[0].authorName
}
this.canStart = true;
this.message = '';
}).catch((err: BusinessError) => {
Logger.error(TAG, `getContentDetailData catch, error.code : ${err.code}, error.message:${err.message}`);
// todo:
// this.title = '旅途平安!这首歌送给即将启程回家的你'
// this.url = 'https://cdnjdout.aikan.pdnews.cn/zhbj-20240127/vod/content/output/f45ef51bb33f4ffd9458f8b386aa3227_opt.mp4'
this.canStart = false;
this.message = '获取播放地址异常';
ToastUtils.showToast(this.message, 1000);
})
.finally(() => {
Logger.debug(TAG, `getContentDetailData finally`);
})
}
}