PlayViewModel.ets
2.22 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
import { BusinessError } from '@ohos.base'
import { Logger, ToastUtils } from 'wdKit'
import { ResponseDTO} from 'wdNetwork'
import { ContentDetailRequest } from 'wdDetailPlayApi'
import { ContentDetailDTO } from 'wdBean'
const TAG = 'PlayViewModel';
@Observed
export class PlayViewModel {
contentId: string
relId: string
relType: string
title?: string
url?: string
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
}
this.title = resDTO.data[0].newsTitle
this.url = resDTO.data[0].videoInfo[0].videoUrl
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`);
})
}
}